kenaragorn / create_flutter_provider_app Goto Github PK
View Code? Open in Web Editor NEWA boilerplate project created in Flutter using Provider and Firebase.
License: MIT License
A boilerplate project created in Flutter using Provider and Firebase.
License: MIT License
Hi,
In this architecture if we wanted to have global parameters for a specific user, stored in firebase, how would you do it?
Make another widget / stream + provider like widgetAuthBuilder, below this one? Or is there a better way? Overload the "flat" user from firebase ?
I'm a little lost, if you can clarify this :)
Thanks
Excellent code. How would you implement the storage service?
Hey, I'm really impressed with this starter architecture. Would be really nice if you added some additional features:
I know that's a lot, but you're doing a great job so far. This boilerplate structure has a high potential of easing the process for many developers.
Thought there was a lot of good stuff in this repo. I've been looking at this one line for a while and curious how it works. You stopped just short of explaining this in your medium article.
In this line databaseBuilder: (_, uid) => FirestoreDatabase(uid: uid),
I understand that FirestoreDatabase
takes a named parameter called uid
, and that the value for that is coming from (_, uid)
. What I'm not following is where the uid for (_, uid)
is actually created and emitted in the first place.
If you have any insights I would appreciate it.
Thanks!
create_flutter_provider_app/lib/main.dart
Line 34 in 8479c6f
Hello,
First of all, thank you for the code, it can have a lot of value.
That being said, I found some issues when trying to start the app.
First I had to go to pubspec.yaml
and do:
assets:
- assets/lang/en.json
- assets/lang/zh.json
fonts:
- family: ProductSans
fonts:
- asset: assets/fonts/Product-Sans-Regular.ttf
- asset: assets/fonts/Product-Sans-Italic.ttf
style: italic
- asset: assets/fonts/Product-Sans-Bold.ttf
weight: 700
- asset: assets/fonts/Product-Sans-Bold-Italic.ttf
style: italic
weight: 700
and change line 27 on the app_localizations.dart
to
await rootBundle.loadString('assets/lang/${locale.languageCode}.json');
or the app wouldn't even start.
Then I had to add
await Firebase.initializeApp();
between lines 15/16 of the main.dart and main_prod.dart, or again, the app wouldn't even start. (Also had to add firebase_core: ^1.6.0
to the pubspec.yaml
, and the import to main.dart
and and main_prod.dart
of course).
Then in line 81 of the my_app.dart
I had to change it to:
return userSnapshot.data?.uid != 'null'
? HomeScreen()
: SignInScreen();
because userSnapshot.hasData
always had "something", and that was causing records to be inserted in the database with uid as null
meaning /user/null/todos/<todo_item_id>
.
But now I can't move on.
I know you say on the README.md
that:
To achieve this, FirestoreDatabase will be re-created everytime onAuthStateChanged changed.
But this doesn't seem to be happening.
Might be due to my changes as mentioned above.
Any help would be much appreciated. Regards to all.
Hi Ken,
just wanna thank you, this project is amazing
I just wanna share my problem with this project
I got this error
Exception: Gradle build failed to produce an .apk file. It's likely that this file was generated under
/home/myusername/Git/create_flutter_provider_app/build, but the tool couldn't find it.
And i do solve it with creating new flutter project then copy build.grade in app folder, and paste it to your amazing template
Why the app can't be exit when back button pressed when I at /home
route? Why must force to close app? I see you used WillPopScope
false
Why not use repository layer to access firestore ?
This will also involve updating the related code. Firebase has changed and also the dart langauge.
Updated:
Used the instructions and inserted the following in register_screen in order to patch the app so that user creation actually lead to a user record in the database. Alas it throws the dreaded "Error: Could not find the correct provider ..." - So what is the deal with register_screen?
FirestoreDatabase firestoreDatabase = Provider.of<FirestoreDatabase>(context);
It seems that the 'userSnapshot.hasData' function is always returning true and the 'SignIn' screen is not called on line 80 of the 'my_app.dart' file. I'm new with flutter, I'm still understanding the use of the 'Provider' approach.
I wanted to test out this project but upon trying to run flutter pub get I receive a long list of dependency issues related to firebase_auth_web. I tried adding the version of firebase_auth_web it requested but that led to further dependency issues.
PS C:\Users\eric1\OneDrive\Desktop\Flutter\create_flutter_provider_app> flutter pub get
Resolving dependencies... (2.7s)
Because firebase_auth >=3.2.0 <3.3.0 depends on firebase_auth_web ^3.2.0 and firebase_auth >=3.3.0 <3.3.1 depends on firebase_auth_web ^3.3.0, firebase_auth
>=3.2.0 <3.3.1 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.1 <3.3.2 depends on firebase_auth_web ^3.3.2 and firebase_auth >=3.3.2 <3.3.3 depends on firebase_auth_web ^3.3.3, firebase_auth
>=3.2.0 <3.3.3 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.3 <3.3.4 depends on firebase_auth_web ^3.3.4 and firebase_auth >=3.3.4 <3.3.5 depends on firebase_auth_web ^3.3.5, firebase_auth
>=3.2.0 <3.3.5 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.5 <3.3.6 depends on firebase_auth_web ^3.3.6 and firebase_auth >=3.3.6 <3.3.8 depends on firebase_auth_web ^3.3.7, firebase_auth
>=3.2.0 <3.3.8 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.8 <3.3.9 depends on firebase_auth_web ^3.3.8 and firebase_auth >=3.3.9 <3.3.12 depends on firebase_auth_web ^3.3.9, firebase_auth
>=3.2.0 <3.3.12 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.12 <3.3.13 depends on firebase_auth_web ^3.3.10 and firebase_auth >=3.3.13 <3.3.14 depends on firebase_auth_web ^3.3.11,
firebase_auth >=3.2.0 <3.3.14 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.14 <3.3.15 depends on firebase_auth_web ^3.3.12 and firebase_auth >=3.3.15 <3.3.17 depends on firebase_auth_web ^3.3.13,
firebase_auth >=3.2.0 <3.3.17 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.17 <3.3.18 depends on firebase_auth_web ^3.3.14 and firebase_auth >=3.3.18 <3.3.19 depends on firebase_auth_web ^3.3.15,
firebase_auth >=3.2.0 <3.3.19 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.3.19 <3.3.20 depends on firebase_auth_web ^3.3.16 and firebase_auth >=3.3.20 <3.4.0 depends on firebase_auth_web ^3.3.17,
firebase_auth >=3.2.0 <3.4.0 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.4.0 <3.4.1 depends on firebase_auth_web ^3.3.18 and firebase_auth >=3.4.1 <3.4.2 depends on firebase_auth_web ^3.3.19, firebase_auth
>=3.2.0 <3.4.2 requires firebase_auth_web ^3.2.0.
And because firebase_auth >=3.4.2 <3.5.0 depends on firebase_auth_web ^4.0.0 and firebase_auth >=3.5.0 <3.5.1 depends on firebase_auth_web ^4.1.0, firebase_auth
>=3.2.0 <3.5.1 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
And because firebase_auth >=3.5.1 <3.6.0 depends on firebase_auth_web ^4.1.1 and firebase_auth >=3.6.0 <3.6.1 depends on firebase_auth_web ^4.2.0, firebase_auth
>=3.2.0 <3.6.1 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
And because firebase_auth >=3.6.1 <3.6.2 depends on firebase_auth_web ^4.2.1 and firebase_auth >=3.6.2 <3.6.3 depends on firebase_auth_web ^4.2.2, firebase_auth
>=3.2.0 <3.6.3 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
And because firebase_auth >=3.6.3 <3.6.4 depends on firebase_auth_web ^4.2.3 and firebase_auth >=3.6.4 <3.7.0 depends on firebase_auth_web ^4.2.4, firebase_auth
>=3.2.0 <3.7.0 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
And because firebase_auth >=3.7.0 <3.8.0 depends on firebase_auth_web ^4.3.0 and firebase_auth >=3.8.0 <3.9.0 depends on firebase_auth_web ^4.4.0, firebase_auth
>=3.2.0 <3.9.0 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
And because firebase_auth >=3.9.0 <3.10.0 depends on firebase_auth_web ^4.4.1 and firebase_auth >=3.10.0 <3.11.0 depends on firebase_auth_web ^4.5.0,
firebase_auth >=3.2.0 <3.11.0 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
(1) So, because firebase_auth >=3.11.0 <3.11.2 depends on firebase_auth_web ^4.6.0 and firebase_auth ^3.11.2 depends on firebase_auth_web ^4.6.1, firebase_auth ^3.2.0
requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0.
Because firebase_auth >=3.1.5 <3.2.0 depends on firebase_auth_web ^3.1.4 and firebase_auth >=3.1.4 <3.1.5 depends on firebase_auth_web ^3.1.3, firebase_auth
>=3.1.4 <3.2.0 requires firebase_auth_web ^3.1.3.
And because firebase_auth >=3.1.3 <3.1.4 depends on firebase_auth_web ^3.1.2 and firebase_auth >=3.1.0 <3.1.2 depends on firebase_auth_web ^3.1.0, firebase_auth
>=3.1.0 <3.1.2-∞ or >=3.1.3 <3.2.0-∞ requires firebase_auth_web ^3.1.0.
And because no versions of firebase_auth match >3.0.2 <3.1.0 and firebase_auth >=3.1.2 <3.1.3 depends on firebase_auth_web ^3.1.1, firebase_auth >3.0.2 <3.2.0
requires firebase_auth_web ^3.1.0.
And because firebase_auth ^3.2.0 requires firebase_auth_web ^3.2.0 or >=4.0.0 <5.0.0 (1), firebase_auth >3.0.2 <4.0.0 requires firebase_auth_web >=3.1.0 <4.0.0 or
>=4.0.0 <5.0.0.
And because firebase_auth 3.0.2 depends on firebase_auth_web ^3.0.1, firebase_auth ^3.0.2 requires firebase_auth_web >=3.0.1 <4.0.0 or >=4.0.0 <5.0.0.
And because firebase_auth_web >=1.0.0 <5.2.2 depends on intl ^0.17.0 and every version of flutter_localizations from sdk depends on intl 0.18.0, firebase_auth
^3.0.2 is incompatible with flutter_localizations from sdk.
So, because noteapp depends on both flutter_localizations from sdk and firebase_auth ^3.0.2, version solving failed.
PS C:\Users\eric1\OneDrive\Desktop\Flutter\create_flutter_provider_app>
Currently cannot compile caused by deprecated support of Android embedding v1. The link supplied explain quite well the changes necessary for the migration.
$ flutter build apk
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. To migrate
your project, follow the steps at:
https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
The detected reason was:
.../android/app/src/main/AndroidManifest.xml uses
`android:name="io.flutter.app.FlutterApplication"`
Build failed due to use of deprecated Android v1 embedding.
Hi Ken,
Thank you for making this. This is a not an issue but rather a question:
I am building a Chat App with Flutter and FireStore. At first I just stream the data directly to Stream Builder and store reusable data like user data in Shared Preferences, but this might cause a lot of calls to the database for non-reusable data. So I search and find out about using provider with Firestore and find your project. My question is, if using Provider, can the data reflect changes in real time if there are changes in the database, like if an user change their name and all people in their friend list can see the changed name? Or in a chat group, if someone send a message, will other see them also or do they have to refresh the data? I know it might not related too much to the project but I am planning on scrapping my current one and use your as a template to build it if it match the above critia.
The issue is when I close and reopen my app, the color theme and language is not set according to my settings, it's always the default.
In lib/my_app.dart
lines 40
locale: languageProviderRef.appLocale,
and 73
themeMode: themeProviderRef.isDarkModeOn
are the issue.
As these are async methods, from lib/providers/language_provider.dart
and lib/providers/theme_provider.dart
respectively, when the app initially runs, the information isn't there yet.
Let me know if anyone has thoughts how to fix it.
I am very new to flutter so Im still trying to wrap my head around how this project is structured and understand how data is flowing. But what I am trying to do is when a new user try's to register an account I want to first query Firestore to see if they have been invited before allowing registration to happen.
My first guess was to simply use Provider of to gain access to the FirestoreDatabase service inside the register_screen.dart file like so:
Widget _buildForm(BuildContext context) { final authProvider = Provider.of<AuthProvider>(context); final firestoreDatabase = Provider.of<FirestoreDatabase>(context, listen: false);
but got and error saying:
Could not find the correct Provider<FirestoreDatabase>
I believe this has something to do with the widget tree hierarchy and how the FirestoreDatabase is not above the register page but im not sure. Any suggestions?
Also a related question I have is FirestoreDatabase does not extend ChangeNotifier so how are we even able to use something like
Provider.of<FirestoreDatabase>(context, listen: false);
when FirestoreDatabase is not a real provider, it doesn't notify any changes? Can any regular class be pulled in with Provider.of ??
Hi Ken
Any plans to apply the changes required for the latest Firebase updates?
Thanks
Bigtaff
I took me way to long to fix this error, so I hope this helps someone else:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.NAME.APPNAME.dev/com.NAME.APPNAME.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.NAME.APPNAME.MainActivity" on path: DexPathList[[zip file "/data/app/com.NAME.APPNAME.dev-XzP2FDlcF7ok_QeihJlBQQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.NAME.APPNAME.dev-XzP2FDlcF7ok_QeihJlBQQ==/lib/x86, /data/app/com.NAME.APPNAME.dev-XzP2FDlcF7ok_QeihJlBQQ==/base.apk!/lib/x86, /system/lib]]
Maybe this error came because I renamed the bundle itentifier in the AndroidManifest files and everywhere else I could find it. This step wasn´t explicitly explained in the setup of the project.
My solution in the end was to also rename the "android/app/src/main/kotlin/com/venturearkstudio/noteapp" folder structure into my bundle identifier ".../com/NAME/APPNAME". And then also in the MainActivity.kt file the "package com.venturearkstudio.noteapp" to "package com.NAME/APPNAME".
Not sure if these steps should be added into the setup instructions or if I made something wrong and then ran into this issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.