From c273df3821b34b96df559739968995aa2a155460 Mon Sep 17 00:00:00 2001 From: Godsend Joseph Date: Sun, 4 Jul 2021 21:39:19 +0100 Subject: [PATCH 1/3] updated packages and migrated app to Flutter 2.0 --- ndole/bond_app/pubspec.lock | 20 ++++++++++---------- ndole/bond_app/pubspec.yaml | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ndole/bond_app/pubspec.lock b/ndole/bond_app/pubspec.lock index 755984a..93c629c 100644 --- a/ndole/bond_app/pubspec.lock +++ b/ndole/bond_app/pubspec.lock @@ -7,7 +7,7 @@ packages: name: another_flushbar url: "https://pub.dartlang.org" source: hosted - version: "1.10.22" + version: "1.10.23" archive: dependency: transitive description: @@ -70,21 +70,21 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.3.0" cloud_firestore_platform_interface: dependency: transitive description: name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.1.0" + version: "5.2.0" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" collection: dependency: transitive description: @@ -133,28 +133,28 @@ packages: name: firebase_auth url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "2.0.0" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.2.3" + version: "5.0.0" firebase_auth_web: dependency: transitive description: name: firebase_auth_web url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "2.0.0" firebase_core: dependency: "direct main" description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" firebase_core_platform_interface: dependency: transitive description: @@ -197,7 +197,7 @@ packages: name: font_awesome_flutter url: "https://pub.dartlang.org" source: hosted - version: "9.0.0" + version: "9.1.0" google_fonts: dependency: "direct main" description: @@ -337,7 +337,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.11.1" petitparser: dependency: transitive description: diff --git a/ndole/bond_app/pubspec.yaml b/ndole/bond_app/pubspec.yaml index 3235033..e33588f 100644 --- a/ndole/bond_app/pubspec.yaml +++ b/ndole/bond_app/pubspec.yaml @@ -18,29 +18,29 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.8.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter - another_flushbar: ^1.10.17 - cloud_firestore: ^2.2.0 - cupertino_icons: ^1.0.2 - firebase_auth: ^1.0.1 - firebase_core: ^1.0.2 - font_awesome_flutter: ^9.0.0 - google_fonts: ^2.0.0 - google_sign_in: ^5.0.1 - http: ^0.13.1 + another_flushbar: ^1.10.23 + cloud_firestore: ^2.3.0 + cupertino_icons: ^1.0.3 + firebase_auth: ^2.0.0 + firebase_core: ^1.3.0 + font_awesome_flutter: ^9.1.0 + google_fonts: ^2.1.0 + google_sign_in: ^5.0.4 + http: ^0.13.3 logger: ^1.0.0 provider: ^5.0.0 - shared_preferences: ^2.0.5 + shared_preferences: ^2.0.6 dev_dependencies: flutter_test: sdk: flutter change_app_package_name: ^1.0.0 - pedantic: ^1.0.0 + pedantic: ^1.11.1 flutter_launcher_icons: ^0.9.0 flutter_icons: From 0a29062f8ce57ec3b166e2f7c7d1ef4f51f183a9 Mon Sep 17 00:00:00 2001 From: Godsend Joseph Date: Mon, 19 Jul 2021 00:11:42 +0100 Subject: [PATCH 2/3] fix broken code and successfully migrated to Flutter 2.0 --- ndole/bond_app/lib/auth/wrapper.dart | 2 +- ndole/bond_app/lib/models/user_models.dart | 12 +++---- .../lib/providers/theme_provider.dart | 21 +++++++------ ndole/bond_app/lib/screens/add_partner.dart | 4 +-- ndole/bond_app/lib/screens/home_screen.dart | 23 +++++++------- ndole/bond_app/lib/screens/tab_view.dart | 2 +- ndole/bond_app/lib/screens/user_profile.dart | 8 ++--- ndole/bond_app/lib/services/api_request.dart | 8 ++--- ndole/bond_app/lib/services/auth.dart | 20 +++++++----- ndole/bond_app/lib/utils/default_button.dart | 17 +++++----- .../lib/utils/firebase_user_call.dart | 31 +++++++++++++++++++ ndole/bond_app/pubspec.lock | 16 +++++----- ndole/bond_app/pubspec.yaml | 8 ++--- 13 files changed, 103 insertions(+), 69 deletions(-) create mode 100644 ndole/bond_app/lib/utils/firebase_user_call.dart diff --git a/ndole/bond_app/lib/auth/wrapper.dart b/ndole/bond_app/lib/auth/wrapper.dart index bcb9c6b..e696ced 100644 --- a/ndole/bond_app/lib/auth/wrapper.dart +++ b/ndole/bond_app/lib/auth/wrapper.dart @@ -7,7 +7,7 @@ import 'package:provider/provider.dart'; class Wrapper extends StatelessWidget { @override Widget build(BuildContext context) { - final user = Provider.of(context); + final user = Provider.of(context); if (user == null) { return GoogleSignInScreen(); } else { diff --git a/ndole/bond_app/lib/models/user_models.dart b/ndole/bond_app/lib/models/user_models.dart index 4b65fbe..a96e3f5 100644 --- a/ndole/bond_app/lib/models/user_models.dart +++ b/ndole/bond_app/lib/models/user_models.dart @@ -1,15 +1,15 @@ class UserModels { - final String uid; + final String? uid; UserModels({this.uid}); } class UsersDetailsModel { - final String uid; - final String name; - final String username; - final String email; - final String photo; + final String? uid; + final String? name; + final String? username; + final String? email; + final String? photo; UsersDetailsModel({ this.uid, diff --git a/ndole/bond_app/lib/providers/theme_provider.dart b/ndole/bond_app/lib/providers/theme_provider.dart index ea104a2..9d5fc88 100644 --- a/ndole/bond_app/lib/providers/theme_provider.dart +++ b/ndole/bond_app/lib/providers/theme_provider.dart @@ -3,33 +3,34 @@ import 'package:shared_preferences/shared_preferences.dart'; class ThemeProvider with ChangeNotifier { final String key = 'appTheme'; - SharedPreferences _pref; - bool _mTheme; + SharedPreferences? _pref; + bool? _mTheme; - bool get mTheme => _mTheme; + bool get mTheme => _mTheme!; ThemeProvider() { _mTheme = false; _loadFromPref(); } - _initPrefs() async { - if (_pref == null) _pref = await SharedPreferences.getInstance(); + Future _initPrefs() async { + await SharedPreferences.getInstance(); } - _loadFromPref() async { + Future _loadFromPref() async { await _initPrefs(); - _mTheme = _pref.getBool(key) ?? false; + + _mTheme = _pref!.getBool(key) ?? false; notifyListeners(); } - _saveToPref() async { + Future _saveToPref() async { await _initPrefs(); - _pref.setBool(key, _mTheme); + _pref!.setBool(key, _mTheme!); } void checkTheme() { - _mTheme = !_mTheme; + _mTheme = !_mTheme!; _saveToPref(); notifyListeners(); } diff --git a/ndole/bond_app/lib/screens/add_partner.dart b/ndole/bond_app/lib/screens/add_partner.dart index bb461ce..13e7b8e 100644 --- a/ndole/bond_app/lib/screens/add_partner.dart +++ b/ndole/bond_app/lib/screens/add_partner.dart @@ -1,4 +1,5 @@ import 'package:bond_app/utils/default_button.dart'; +import 'package:bond_app/utils/firebase_user_call.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -9,7 +10,6 @@ class AddPartnerScreen extends StatefulWidget { } class _AddPartnerScreenState extends State { - final FirebaseAuth _auth = FirebaseAuth.instance; @override Widget build(BuildContext context) { return Scaffold( @@ -36,7 +36,7 @@ class _AddPartnerScreenState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(80), image: DecorationImage( - image: NetworkImage('${_auth.currentUser.photoURL}'), + image: NetworkImage(userImage().toString()), fit: BoxFit.cover, ), ), diff --git a/ndole/bond_app/lib/screens/home_screen.dart b/ndole/bond_app/lib/screens/home_screen.dart index 6c23220..c692dc5 100644 --- a/ndole/bond_app/lib/screens/home_screen.dart +++ b/ndole/bond_app/lib/screens/home_screen.dart @@ -14,7 +14,7 @@ class _HomeScreenState extends State { final TextEditingController _email = TextEditingController(); - showAddPartnerDialog() { + Dialog? showAddPartnerDialog() { showDialog( context: context, builder: (_) { @@ -32,10 +32,10 @@ class _HomeScreenState extends State { TextFormField( controller: _email, validator: (val) { - if (val.isEmpty) { - return 'Please enter an Email'; - } else { + if (val != null && val.isNotEmpty) { return null; + } else { + return 'Please enter an Email'; } }, decoration: InputDecoration( @@ -57,7 +57,7 @@ class _HomeScreenState extends State { TextButton( onPressed: () { var form = _formKey.currentState; - if (form.validate()) { + if (form != null && form.validate()) { Navigator.pop(context); } }, @@ -70,11 +70,10 @@ class _HomeScreenState extends State { } // function to get only first name - String getOnlyFirstName() { - var mainFromFirebase = _auth.currentUser.displayName; + String? getOnlyFirstName() { + String mainFromFirebase = _auth.currentUser!.displayName.toString(); String firstUserName = mainFromFirebase.substring(0, mainFromFirebase.indexOf(' ')); - return firstUserName; } @@ -105,7 +104,7 @@ class _HomeScreenState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(80), border: Border.all( - color: Colors.grey[200], + color: Colors.grey.shade200, style: BorderStyle.solid, width: 8, ), @@ -143,19 +142,19 @@ class _HomeScreenState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(80), border: Border.all( - color: Colors.grey[200], + color: Colors.grey.shade200, style: BorderStyle.solid, width: 8, ), image: DecorationImage( image: NetworkImage( - '${_auth.currentUser.photoURL}'), + '${_auth.currentUser!.photoURL}'), fit: BoxFit.cover, ), ), ), Text( - getOnlyFirstName(), + getOnlyFirstName().toString(), style: GoogleFonts.roboto( fontSize: 20, ), diff --git a/ndole/bond_app/lib/screens/tab_view.dart b/ndole/bond_app/lib/screens/tab_view.dart index 331208d..442ecbd 100644 --- a/ndole/bond_app/lib/screens/tab_view.dart +++ b/ndole/bond_app/lib/screens/tab_view.dart @@ -10,7 +10,7 @@ class TabView extends StatefulWidget { } class _TabViewState extends State { - final List> _pages = [ + final List> _pages = [ { // we will do the checking for if the user has a partner or not // then push to to HomeScreen() else Push to AddPartnerScreen() diff --git a/ndole/bond_app/lib/screens/user_profile.dart b/ndole/bond_app/lib/screens/user_profile.dart index 1957712..c4b8c15 100644 --- a/ndole/bond_app/lib/screens/user_profile.dart +++ b/ndole/bond_app/lib/screens/user_profile.dart @@ -39,7 +39,7 @@ class _UserProfileState extends State { child: CircleAvatar( backgroundColor: Colors.grey[200], backgroundImage: - NetworkImage('${_auth.currentUser.photoURL}'), + NetworkImage('${_auth.currentUser!.photoURL}'), // child: , ), ), @@ -47,7 +47,7 @@ class _UserProfileState extends State { height: 30, ), Text( - '${_auth.currentUser.displayName}', + '${_auth.currentUser!.displayName}', style: GoogleFonts.nunito( fontSize: 20, ), @@ -91,7 +91,7 @@ class _UserProfileState extends State { ), ), Text( - '${_auth.currentUser.displayName}', + '${_auth.currentUser!.displayName}', style: GoogleFonts.nunito( fontSize: 18, ), @@ -113,7 +113,7 @@ class _UserProfileState extends State { ), ), Text( - '${_auth.currentUser.email}', + '${_auth.currentUser!.email}', style: GoogleFonts.nunito( fontSize: 18, ), diff --git a/ndole/bond_app/lib/services/api_request.dart b/ndole/bond_app/lib/services/api_request.dart index 0f678ce..fca31af 100644 --- a/ndole/bond_app/lib/services/api_request.dart +++ b/ndole/bond_app/lib/services/api_request.dart @@ -13,11 +13,11 @@ class ApiRequest { var req = await http.post( Uri.parse(authUser), body: { - 'uid': _auth.currentUser.uid, - 'name': _auth.currentUser.displayName, + 'uid': _auth.currentUser!.uid, + 'name': _auth.currentUser!.displayName, 'username': '', - 'photo': _auth.currentUser.photoURL, - 'email': _auth.currentUser.email, + 'photo': _auth.currentUser!.photoURL, + 'email': _auth.currentUser!.email, }, ); var res = json.decode(req.body); diff --git a/ndole/bond_app/lib/services/auth.dart b/ndole/bond_app/lib/services/auth.dart index 3a4044f..ee42386 100644 --- a/ndole/bond_app/lib/services/auth.dart +++ b/ndole/bond_app/lib/services/auth.dart @@ -7,33 +7,39 @@ class AuthService { final FirebaseAuth _auth = FirebaseAuth.instance; //create user object based on firebase user - UserModels _userFromFirebaseUser(User user) { + UserModels? _userFromFirebaseUser(User? user) { return user != null ? UserModels(uid: user.uid) : null; } //auth change user stream - Stream get user { + Stream get user { return _auth.authStateChanges().map(_userFromFirebaseUser); } + String? userUID() { + User? user = _auth.currentUser; + if (user != null) { + return user.uid; + } + } + //sign in with Google Future signUpWithGoogle(context) async { try { // Trigger the authentication flow - final GoogleSignInAccount googleUser = await GoogleSignIn().signIn(); + GoogleSignInAccount? googleUser = await GoogleSignIn().signIn(); // Obtain the auth details from the request - final GoogleSignInAuthentication googleAuth = - await googleUser.authentication; + GoogleSignInAuthentication? googleAuth = await googleUser!.authentication; // Create a new credential - final GoogleAuthCredential credential = GoogleAuthProvider.credential( + final credential = GoogleAuthProvider.credential( accessToken: googleAuth.accessToken, idToken: googleAuth.idToken, ); await _auth.signInWithCredential(credential).then((result) { - User user = result.user; + User? user = result.user; return _userFromFirebaseUser(user); }).catchError((err) { print('${err.toString()}.................'); diff --git a/ndole/bond_app/lib/utils/default_button.dart b/ndole/bond_app/lib/utils/default_button.dart index 329f3d4..abdb9ac 100644 --- a/ndole/bond_app/lib/utils/default_button.dart +++ b/ndole/bond_app/lib/utils/default_button.dart @@ -1,19 +1,16 @@ import 'package:bond_app/const_values.dart'; import 'package:flutter/material.dart'; -class DefaultButton extends StatefulWidget { - final String title; - final Function onPress; +class DefaultButton extends StatelessWidget { + final String? title; + final VoidCallback? onPress; DefaultButton({ + Key? key, @required this.title, @required this.onPress, - }); - @override - _DefaultButtonState createState() => _DefaultButtonState(); -} + }) : super(key: key); -class _DefaultButtonState extends State { @override Widget build(BuildContext context) { return Container( @@ -25,9 +22,9 @@ class _DefaultButtonState extends State { ), child: TextButton( style: ButtonStyle(), - onPressed: widget.onPress, + onPressed: onPress, child: Text( - widget.title, + title!, style: TextStyle( color: Colors.white, ), diff --git a/ndole/bond_app/lib/utils/firebase_user_call.dart b/ndole/bond_app/lib/utils/firebase_user_call.dart new file mode 100644 index 0000000..cdeffb3 --- /dev/null +++ b/ndole/bond_app/lib/utils/firebase_user_call.dart @@ -0,0 +1,31 @@ +// import 'package:firebase_auth/firebase_auth.dart'; + +// final FirebaseAuth _auth = FirebaseAuth.instance; + +// String? userUID() { +// User? user = _auth.currentUser; +// if (user != null) { +// return user.uid; +// } +// } + +// String? userImage() { +// User? user = _auth.currentUser; +// if (user != null) { +// return user.photoURL; +// } +// } + +// String? userName() { +// User? user = _auth.currentUser; +// if (user != null) { +// return user.displayName; +// } +// } + +// String? userEmail() { +// User? user = _auth.currentUser; +// if (user != null) { +// return user.email; +// } +// } diff --git a/ndole/bond_app/pubspec.lock b/ndole/bond_app/pubspec.lock index 93c629c..9a1a13a 100644 --- a/ndole/bond_app/pubspec.lock +++ b/ndole/bond_app/pubspec.lock @@ -7,7 +7,7 @@ packages: name: another_flushbar url: "https://pub.dartlang.org" source: hosted - version: "1.10.23" + version: "1.10.24" archive: dependency: transitive description: @@ -70,21 +70,21 @@ packages: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" cloud_firestore_platform_interface: dependency: transitive description: name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.2.0" + version: "5.3.0" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.3.0" collection: dependency: transitive description: @@ -133,28 +133,28 @@ packages: name: firebase_auth url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.1" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "6.0.0" firebase_auth_web: dependency: transitive description: name: firebase_auth_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "3.0.0" firebase_core: dependency: "direct main" description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.4.0" firebase_core_platform_interface: dependency: transitive description: diff --git a/ndole/bond_app/pubspec.yaml b/ndole/bond_app/pubspec.yaml index e33588f..f318dd7 100644 --- a/ndole/bond_app/pubspec.yaml +++ b/ndole/bond_app/pubspec.yaml @@ -23,11 +23,11 @@ environment: dependencies: flutter: sdk: flutter - another_flushbar: ^1.10.23 - cloud_firestore: ^2.3.0 + another_flushbar: ^1.10.24 + cloud_firestore: ^2.4.0 cupertino_icons: ^1.0.3 - firebase_auth: ^2.0.0 - firebase_core: ^1.3.0 + firebase_auth: ^3.0.1 + firebase_core: ^1.4.0 font_awesome_flutter: ^9.1.0 google_fonts: ^2.1.0 google_sign_in: ^5.0.4 From 766552a88c475c62fc160e685a19ff0fe8d2d3ae Mon Sep 17 00:00:00 2001 From: Godsend Joseph Date: Mon, 19 Jul 2021 00:16:15 +0100 Subject: [PATCH 3/3] fix broken code and successfully migrated to Flutter 2.0 --- ndole/bond_app/lib/screens/add_partner.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ndole/bond_app/lib/screens/add_partner.dart b/ndole/bond_app/lib/screens/add_partner.dart index 13e7b8e..3fd5783 100644 --- a/ndole/bond_app/lib/screens/add_partner.dart +++ b/ndole/bond_app/lib/screens/add_partner.dart @@ -1,5 +1,5 @@ import 'package:bond_app/utils/default_button.dart'; -import 'package:bond_app/utils/firebase_user_call.dart'; +// import 'package:bond_app/utils/firebase_user_call.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -10,6 +10,7 @@ class AddPartnerScreen extends StatefulWidget { } class _AddPartnerScreenState extends State { + final FirebaseAuth _auth = FirebaseAuth.instance; @override Widget build(BuildContext context) { return Scaffold( @@ -36,7 +37,7 @@ class _AddPartnerScreenState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(80), image: DecorationImage( - image: NetworkImage(userImage().toString()), + image: NetworkImage('${_auth.currentUser!.photoURL}'), fit: BoxFit.cover, ), ),