Im having problem in the path provider dependencies in flutter.
I've been trying to find a solution for this for almost 2 day now..
please help me..
My dependencies
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
hive: ^1.4.1+1
hive_flutter: ^0.3.0+2
path_provider: ^1.6.5
http: ^0.12.2
My Code (even without code its running the error as long as a add the path provider)
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:convert';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
void main() async {
//Hive.initFlutter();
WidgetsFlutterBinding.ensureInitialized();
//final appDocDir = await getApplicationDocumentsDirectory();
// Hive.init(appDocDir.path);
var box = await Hive.openBox('employee');
runApp(
MaterialApp(home: Home()),
);
}
class Home extends StatefulWidget {
Home({Key key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sample'),
),
body: Center(),
);
}
}
I've resolved this using by doing flutter pub downgrade in the terminal
Related
I am trying to create a SignIn page with Firebase authentication, but this error is happening in main.dart when I run the code:
This is the code: from main.dart:
import 'package:app_mypocket/services/auth_service.dart';
import 'package:app_mypocket/telas/home/homepage.dart';
import 'package:app_mypocket/telas/login/telalogin.dart';
[import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Pocket',
debugShowCheckedModeBanner: false,
theme: ThemeData(
),
home: HomePage(),
//routes: routes,
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) => Scaffold(
body: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.hasData){
return HomePage();
} else{
return TelaLogin();
}
})
);
}
My pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
intl:
provider: ^6.0.4
shared_preferences: ^2.0.6
hive: ^2.0.4
hive_flutter: ^1.1.0
path_provider: ^2.0.2
sqflite: ^2.0.0+3
fl_chart: ^0.55.2
firebase_core: ^2.1.1
firebase_auth: ^4.1.0
cloud_firestore: ^4.0.3
Also, I have created a user manually in my project on the firebase website, so I am trying to logIn.
When logging into Firebase you normally provide options, like:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
// Initialize Firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
These firebase_options are generated by running "flutterfire configure" (previously firebase configure iirc).
I think you forget this specific step. See the guide: https://firebase.google.com/docs/flutter/setup?platform=ios
The configuration file contains information about the apiKey, appId, projectId, bundle/app name and much more. Not providing it, will lead to a default/blank/unusable app.
So I want to open an SVG file in my main.dart file and for that, I'm using the File class and the readAsStringSync() method. But it seems like the File object cannot open the file.
And when I try to do the same thing outside of the flutter project, it seems to be working fine.
Here is the folder structure that I'm using in both the flutter project and the dart project.
lib
|_ main.dart
|_ world.svg
Here is the main.dart of the flutter project:
import 'dart:io';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
final xml = File('world.svg').readAsStringSync();
print(xml);
return Scaffold(
appBar: AppBar(title: Text('Testing')),
);
}
}
Error
And here is the main.dart of the dart project:
import 'dart:io';
void main() {
String file = File('world.svg').readAsStringSync();
print(file.length);
}
Output
In the process of learning bloc and have started to create a basic state and cubit but I am now getting the following error.
I should be seeing a grey screen in emulation mode instead, I see the following red error.
_TypeError (type 'Null' is not a subtype of type 'Color' of 'function result')
I'm not quite sure why, since the first state should be Color.grey?
Main.dart
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:bloctest/cubit/color_cubit.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: BlocProvider(
create: (context) => ColorCubit(),
child: BlocBuilder<ColorCubit, ColorState>(builder: (context, state) {
return Container(
color: state.color,
child: FloatingActionButton(
onPressed: () {
print('we will change the state soon');
},
));
}),
),
);
}
}
color_state.dart
part of 'color_cubit.dart';
abstract class ColorState extends Equatable {
final Color color;
const ColorState(this.color);
#override
List<Object> get props => [];
}
class ColorInitial extends ColorState {
const ColorInitial() : super(Colors.grey);
}
color_cubit.dart
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
part 'color_state.dart';
class ColorCubit extends Cubit<ColorState> {
ColorCubit() : super(const ColorInitial());
}
in my app i want to detect in the splashscreen if this app is started for the first time.
For that i want to use the hive nosql package.
After that if the app is started for the first time it will open the welcome page and if not the login page.
main.dart
import 'package:flutter_config/flutter_config.dart';
import 'package:flutter/material.dart';
import 'package:app/pages/splash/splash_page.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'config/theme/theme.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterConfig.loadEnvVariables();
await Hive.initFlutter();
await Hive.openBox('settings');
runApp(const App());
}
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
#override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
#override
void dispose() async {
Hive.close();
super.dispose();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
debugShowCheckedModeBanner: false,
theme: lightThemeData(context),
darkTheme: darkThemeData(context),
home: const SplashPage(),
);
}
}
splash_page.dart
import 'package:flutter/material.dart';
import 'package:app/pages/login/login_page.dart';
import 'package:app/pages/welcome/welchome_page.dart';
import 'package:app/services/settings_service.dart';
class SplashPage extends StatefulWidget {
const SplashPage({Key? key}) : super(key: key);
#override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
#override
Widget build(BuildContext context) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) =>
Settings().isFirstTime ? const WelcomePage() : const LoginPage(),
),
);
return const Scaffold(
body: Center(
child: SizedBox(
width: 125,
height: 125,
child: Icon(Icons.clear),
),
),
);
}
}
there i call the function "var _isFirstTime = Settings().isFirstTime;" it should return me a bool
settings_service.dart
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
class Settings {
final Box _settingsStorage = Hive.box('settings');
get isFirstTime {
if (_settingsStorage.get('firstRun')) {
return true;
} else {
_settingsStorage.put('firstRun', true);
}
return false;
}
}
i got this error:
════════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building SplashPage(dirty, state: _SplashPageState#261ae):
type 'Null' is not a subtype of type 'bool'
how can i solve this? later i would like to use the settings service for other settings as well ...
In the setting_service.dart,
I think this line -> _settingsStorage.get('firstRun'), is returning null. From what I understand what you should do is that whenever you get firstRun as null, you should assign it true.
if (_settingsStorage.get('firstRun') ?? true) {
return _settingsStorage.get('firstRun') ?? true;
}
I have created an app to display html file with flutter_inappwebview plugin but i got errors as below:
pubspec.yaml
flutter_inappwebview: ^2.1.0
here is my main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
InAppWebViewController webView;
String url = "";
double progress = 0;
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
return Container(
height: 200,
child: InAppWebView(
initialUrl: 'https://www.google.com',
),
);
}
}
when I run the code the app unfortunately stop.
This is an error in Emulator.
This is an error in Android Studio 3.5.3
Any solutions thanks?
After looking at issue in github issue link, here is the solution:
From
dependencies:
flutter_inappwebview: ^2.1.0+1
To
dependencies:
flutter_inappwebview:
git:
url: https://github.com/pichillilorenzo/flutter_inappwebview.git
Then run flutter clean and then run the app. It should solve the problem.