From 41874e9b17a7234f552a53136e403ffaa98bc543 Mon Sep 17 00:00:00 2001 From: Scott Clampet Date: Mon, 6 May 2019 10:51:23 -0600 Subject: [PATCH] fix(entire app): fix small design bugs, keyboard focusing issue, store theme on device, test sharing re #116, re #115, re #96, re # 46 --- fude_app/lib/main.dart | 7 +- .../forgot-password/forgotpass_button.dart | 2 +- fude_app/lib/pages/auth/login/login.dart | 111 +++++++----- .../pages/auth/signup/forgotpass_link.dart | 2 +- fude_app/lib/pages/auth/signup/signup.dart | 1 + fude_app/lib/pages/home/home.dart | 166 ++++++++++-------- fude_app/lib/pages/home/home_page_jar.dart | 11 +- fude_app/lib/pages/jars/jar.dart | 89 ++++++---- fude_app/lib/pages/jars/jar_add.dart | 31 ++-- fude_app/lib/pages/jars/jar_edit.dart | 71 +++++--- fude_app/lib/scoped-models/jar.dart | 48 ++++- fude_app/lib/scoped-models/user.dart | 23 +-- .../lib/widgets/form-inputs/input_fields.dart | 1 + fude_app/lib/widgets/forms/add_jar.dart | 12 +- .../lib/widgets/forms/add_user_to_jar.dart | 4 +- fude_app/lib/widgets/forms/edit_jar.dart | 5 +- fude_app/lib/widgets/logo.dart | 2 + 17 files changed, 355 insertions(+), 231 deletions(-) diff --git a/fude_app/lib/main.dart b/fude_app/lib/main.dart index ee78832..8ebb0d2 100644 --- a/fude_app/lib/main.dart +++ b/fude_app/lib/main.dart @@ -25,9 +25,12 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { MainModel _model = MainModel(); - _model.fetchUser(); - return ScopedModel(model: _model, child: _buildApp(context)); + _model.getThemeFromPrefs(); + return ScopedModel( + model: _model, + child: _buildApp(context), + ); } } diff --git a/fude_app/lib/pages/auth/forgot-password/forgotpass_button.dart b/fude_app/lib/pages/auth/forgot-password/forgotpass_button.dart index 7f2baec..92fe026 100644 --- a/fude_app/lib/pages/auth/forgot-password/forgotpass_button.dart +++ b/fude_app/lib/pages/auth/forgot-password/forgotpass_button.dart @@ -14,7 +14,7 @@ class ForgotPassButton extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10.0)), ), child: Text( - "reset", + "reset password", style: TextStyle( color: Theme.of(context).secondaryHeaderColor, fontSize: 20.0, diff --git a/fude_app/lib/pages/auth/login/login.dart b/fude_app/lib/pages/auth/login/login.dart index 4f1d72c..73409b7 100644 --- a/fude_app/lib/pages/auth/login/login.dart +++ b/fude_app/lib/pages/auth/login/login.dart @@ -76,16 +76,28 @@ class _LoginPageState extends State with TickerProviderStateMixin { context: context, builder: (BuildContext context) { return AlertDialog( - title: Text('Oops!'), - content: Text(userMessage), - actions: [ - FlatButton( - child: Text('Okay'), - onPressed: () { - Navigator.of(context).pop(); - }, - ) - ], + shape: + RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)), + backgroundColor: Theme.of(context).primaryColor, + title: Text( + 'Aw Geeze!', + style: TextStyle( + color: Theme.of(context).secondaryHeaderColor, + fontWeight: FontWeight.bold, + fontSize: 30, + letterSpacing: 8, + ), + ), + content: Text( + userMessage, + style: TextStyle( + color: Theme.of(context).secondaryHeaderColor, + // fontWeight: FontWeight.bold, + fontSize: 20, + letterSpacing: 3, + ), + ), + actions: [], ); }, ); @@ -99,49 +111,52 @@ class _LoginPageState extends State with TickerProviderStateMixin { builder: (BuildContext context, Widget child, MainModel model) { return Scaffold( body: Container( - child: Container( - decoration: BoxDecoration( - color: Theme.of(context).secondaryHeaderColor), - child: ListView( - padding: EdgeInsets.all(0.0), + decoration: + BoxDecoration(color: Theme.of(context).secondaryHeaderColor), + child: ListView( + padding: EdgeInsets.all(0.0), + children: [ + Stack( + alignment: AlignmentDirectional.bottomCenter, children: [ - Stack( - alignment: AlignmentDirectional.bottomCenter, + Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ - Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Logo(), - model.resetLinkSent - ? Text( - 'check your email!', - style: TextStyle( - color: Theme.of(context).primaryColor), - ) - : Container(), - FormContainer( - formKey: formKey, - updateEmail: updateEmail, - updatePassword: updatePassword, - isLogin: isLogin), - SignUp() - ], - ), - Padding( - padding: EdgeInsets.only(bottom: 50.0), - child: InkWell( - onTap: () { - setState(() { - animationStatus = 1; - }); - _submitForm(login: model.login); - }, - child: LoginInButton()), - ) + Logo(), + model.resetLinkSent + ? Text( + 'check your email!', + style: TextStyle( + color: Theme.of(context).primaryColor), + ) + : Container(), + FormContainer( + formKey: formKey, + updateEmail: updateEmail, + updatePassword: updatePassword, + isLogin: isLogin), + SignUp() ], ), + Padding( + padding: EdgeInsets.only(bottom: 50.0), + child: InkWell( + onTap: () { + setState(() { + animationStatus = 1; + }); + _submitForm(login: model.login); + }, + child: !model.isLoading + ? LoginInButton() + : CircularProgressIndicator( + strokeWidth: 6, + )), + ) ], - ))), + ), + ], + )), ); }); } diff --git a/fude_app/lib/pages/auth/signup/forgotpass_link.dart b/fude_app/lib/pages/auth/signup/forgotpass_link.dart index 095bf76..992f86f 100644 --- a/fude_app/lib/pages/auth/signup/forgotpass_link.dart +++ b/fude_app/lib/pages/auth/signup/forgotpass_link.dart @@ -21,7 +21,7 @@ class ForgotPassword extends StatelessWidget { style: TextStyle( fontWeight: FontWeight.w300, letterSpacing: 0.5, - color: Colors.white, + color: Theme.of(context).primaryColor, fontSize: 12.0), ), ), diff --git a/fude_app/lib/pages/auth/signup/signup.dart b/fude_app/lib/pages/auth/signup/signup.dart index 3ccc991..133201b 100644 --- a/fude_app/lib/pages/auth/signup/signup.dart +++ b/fude_app/lib/pages/auth/signup/signup.dart @@ -125,6 +125,7 @@ class _SignUpState extends State with TickerProviderStateMixin { setState(() { animationStatus = 1; }); + model.resetUsersJars(); _submitForm(register: model.register); }, child: SignUpButton()), diff --git a/fude_app/lib/pages/home/home.dart b/fude_app/lib/pages/home/home.dart index dd1b9b8..50d4ce5 100644 --- a/fude_app/lib/pages/home/home.dart +++ b/fude_app/lib/pages/home/home.dart @@ -24,12 +24,25 @@ class _HomePageState extends State { super.initState(); } + void _openJar(int index) { + widget.model.getJarBySelectedId(widget.model.usersJars[index].documentID); + Timer(Duration(milliseconds: 500), () { + Navigator.push( + context, + PageTransition( + curve: Curves.linear, + type: PageTransitionType.downToUp, + child: JarPage(model: widget.model), + ), + ); + Timer(Duration(seconds: 2), () => widget.model.resetIsLoading()); + }); + } + @override Widget build(BuildContext context) { final double width = MediaQuery.of(context).size.width; final double height = MediaQuery.of(context).size.height; - // print('LIST in BUILD ${widget.model.usersJars[0].runtimeType}'); - return Scaffold( appBar: AppBar( title: Container( @@ -55,85 +68,90 @@ class _HomePageState extends State { automaticallyImplyLeading: false, ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: FloatingActionButton( - shape: CircleBorder(), - elevation: 0, - backgroundColor: Theme.of(context).primaryColor, - foregroundColor: Theme.of(context).primaryColor, - highlightElevation: 0, - onPressed: () => widget.model.invertTheme(), - child: - Theme.of(context).primaryColor == Color.fromRGBO(242, 242, 242, 1) - ? Image.asset( - 'assets/IconDark.png', - height: height * 0.2, - width: width * 0.2, - ) - : Image.asset( - 'assets/IconLight.png', - height: height * 0.2, - width: width * 0.2, - ), + floatingActionButton: Padding( + padding: EdgeInsets.only(bottom: height * 0.08), + child: FloatingActionButton( + shape: CircleBorder(), + elevation: 0, + backgroundColor: Theme.of(context).primaryColor, + foregroundColor: Theme.of(context).primaryColor, + highlightElevation: 0, + onPressed: () => widget.model.invertTheme(), + child: !widget.model.isLoading + ? Theme.of(context).primaryColor == + Color.fromRGBO(242, 242, 242, 1) + ? Image.asset( + 'assets/IconDark.png', + height: height * 0.2, + width: width * 0.2, + ) + : Image.asset( + 'assets/IconLight.png', + height: height * 0.2, + width: width * 0.2, + ) + : Container(), + ), ), bottomNavigationBar: BottomAppBar( color: Theme.of(context).primaryColor, elevation: 0, child: Container(height: 20), ), - body: Container( - height: height, - width: width, - decoration: BoxDecoration( - color: Theme.of(context).primaryColor, - ), - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - widget.model.usersJars.length == 0 - ? Center( - child: CircularProgressIndicator(), - ) - : Container( - margin: EdgeInsets.fromLTRB(0, height * 0.1, 0, 0), - width: width, - height: height * 0.55, - child: PageView.builder( - reverse: false, - pageSnapping: true, - controller: PageController( - keepPage: false, - viewportFraction: 0.88, - initialPage: 0), - itemCount: widget.model.usersJars.length, - itemBuilder: (context, index) { - return index == 0 - ? HomePageJar( - model: widget.model, title: 'Add Jar') - : GestureDetector( - onTap: () { - widget.model.getJarBySelectedId(widget - .model.usersJars[index].documentID); - Timer(Duration(milliseconds: 500), () { - Navigator.push( - context, - PageTransition( - curve: Curves.linear, - type: PageTransitionType.downToUp, - child: JarPage(model: widget.model), - ), + body: !widget.model.isLoading + ? Container( + height: height, + width: width, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + ), + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ + widget.model.usersJars.length == 0 + ? Center( + child: CircularProgressIndicator(), + ) + : Container( + margin: EdgeInsets.fromLTRB(0, height * 0.1, 0, 0), + width: width, + height: height * 0.55, + child: PageView.builder( + reverse: false, + pageSnapping: true, + controller: PageController( + keepPage: false, + viewportFraction: 0.8, + initialPage: 0), + itemCount: widget.model.usersJars.length, + itemBuilder: (context, index) { + return index == 0 + ? HomePageJar( + model: widget.model, title: 'Add Jar') + : GestureDetector( + onTap: () => _openJar(index), + child: HomePageJar( + model: widget.model, + jar: widget.model.usersJars[index], + title: null), ); - }); - }, - child: HomePageJar( - model: widget.model, - jar: widget.model.usersJars[index], - title: null), - ); - }), - ) - ], - ), - ), + }), + ) + ], + ), + ) + : Container( + height: height, + width: width, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + ), + child: Center( + child: CircularProgressIndicator( + strokeWidth: 6, + ), + ), + ), ); } } diff --git a/fude_app/lib/pages/home/home_page_jar.dart b/fude_app/lib/pages/home/home_page_jar.dart index bc027e2..ff719ce 100644 --- a/fude_app/lib/pages/home/home_page_jar.dart +++ b/fude_app/lib/pages/home/home_page_jar.dart @@ -76,13 +76,12 @@ class HomePageJar extends StatelessWidget { color: Theme.of(context).textTheme.subhead.color, onPressed: () { model.categoryChildren = []; - model.getJarBySelectedId(jar.documentID); Navigator.push( context, PageTransition( curve: Curves.linear, type: PageTransitionType.downToUp, - child: EditJarPage(model: model), + child: EditJarPage(model: model, jar: jar), ), ); }, @@ -129,8 +128,9 @@ class HomePageJar extends StatelessWidget { @override Widget build(BuildContext context) { Image jarImage = Image( - image: jar != null ? NetworkImage( - jar.data['image']) : AssetImage('assets/logo.png'), + image: jar != null + ? NetworkImage(jar.data['image']) + : AssetImage('assets/logo.png'), fit: BoxFit.cover, alignment: FractionalOffset( 0.5, @@ -175,7 +175,8 @@ class HomePageJar extends StatelessWidget { child: Material( elevation: model.darkTheme ? 4.0 : 8, shadowColor: Theme.of(context).secondaryHeaderColor, - borderRadius: BorderRadius.all(Radius.circular(30)), + color: Theme.of(context).primaryColor, + borderRadius: BorderRadius.all(Radius.circular(35)), child: Stack( fit: StackFit.expand, children: [ diff --git a/fude_app/lib/pages/jars/jar.dart b/fude_app/lib/pages/jars/jar.dart index 6440985..6392a9f 100644 --- a/fude_app/lib/pages/jars/jar.dart +++ b/fude_app/lib/pages/jars/jar.dart @@ -9,6 +9,7 @@ import 'dart:ui'; import 'package:fude/scoped-models/main.dart'; import 'package:fude/pages/jars/jar_notes.dart'; import 'package:fude/pages/jars/category_card.dart'; +import 'package:fude/pages/home/home.dart'; import 'package:fude/helpers/randomNoteModal.dart'; class JarPage extends StatefulWidget { @@ -71,12 +72,9 @@ class _JarPageState extends State { child: Container( decoration: BoxDecoration( image: DecorationImage( - image: NetworkImage( - widget.model.selectedJar.data['image'] != null - ? widget.model.selectedJar.data['image'] - : 'https://firebasestorage.googleapis.com/v0/b/fude-app.appspot.com/o/Scoot-01.png?alt=media&token=53fc26de-7c61-4076-a0cb-f75487779604', - scale: 0.5, - ), + image: widget.model.selectedJar.data['image'] != null + ? NetworkImage(widget.model.selectedJar.data['image']) + : AssetImage('assets/logo.png'), fit: BoxFit.fitWidth, ), ), @@ -94,7 +92,7 @@ class _JarPageState extends State { colors: !widget.model.darkTheme ? [ Color.fromRGBO(242, 242, 242, 0.5), - Color.fromRGBO(40, 40, 40, 0.5), + Color.fromRGBO(40, 40, 40, 0.8), ] : [ Color.fromRGBO(40, 40, 40, 0.5), @@ -164,7 +162,16 @@ class _JarPageState extends State { iconSize: 40, onPressed: () { _swiperVisible = false; - Navigator.pop(context); + Navigator.pop( + context, + PageTransition( + curve: Curves.linear, + type: + PageTransitionType.upToDown, + child: HomePage( + model: widget.model), + ), + ); }), ), ), @@ -198,7 +205,7 @@ class _JarPageState extends State { ), ), Positioned( - top: height * 0.24, + top: height * 0.21, left: width * 0.07, right: width * 0.07, child: AnimatedOpacity( @@ -213,33 +220,53 @@ class _JarPageState extends State { ), ), Positioned( - top: height * 0.46, + top: height * 0.43, left: width * 0.07, right: width * 0.07, child: AnimatedOpacity( opacity: _swiperVisible ? 1.0 : 0.0, duration: Duration(milliseconds: 1000), - child: model.selectedJar.data['categories'].length > 0 ?Text( - 'SELECT CATEGORY', - style: TextStyle( - color: - Theme.of(context).secondaryHeaderColor, - fontWeight: FontWeight.bold, - fontSize: 14, - letterSpacing: 3, - ), - textAlign: TextAlign.center, - ) : Text( - "YOU DON'T HAVE ANY CATEGORIES YET", - style: TextStyle( - color: - Theme.of(context).secondaryHeaderColor, - fontWeight: FontWeight.bold, - fontSize: 14, - letterSpacing: 3, - ), - textAlign: TextAlign.center, - ), + child: model.selectedJar.data['categories'] + .length > + 0 + ? Column( + children: [ + Text( + 'SELECT A CATEGORY', + style: TextStyle( + color: Theme.of(context) + .secondaryHeaderColor, + fontWeight: FontWeight.bold, + fontSize: 14, + letterSpacing: 3, + ), + textAlign: TextAlign.center, + ), + SizedBox(height: height * 0.01,), + Text( + 'TO PULL A RANDOM IDEA', + style: TextStyle( + color: Theme.of(context) + .secondaryHeaderColor, + fontWeight: FontWeight.bold, + fontSize: 14, + letterSpacing: 3, + ), + textAlign: TextAlign.center, + ), + ], + ) + : Text( + "YOU DON'T HAVE ANY CATEGORIES YET", + style: TextStyle( + color: Theme.of(context) + .secondaryHeaderColor, + fontWeight: FontWeight.bold, + fontSize: 14, + letterSpacing: 3, + ), + textAlign: TextAlign.center, + ), ), ), //SWIPER diff --git a/fude_app/lib/pages/jars/jar_add.dart b/fude_app/lib/pages/jars/jar_add.dart index c7d9acb..0f7f1f0 100644 --- a/fude_app/lib/pages/jars/jar_add.dart +++ b/fude_app/lib/pages/jars/jar_add.dart @@ -16,6 +16,8 @@ class _JarPageState extends State { final GlobalKey formKey = GlobalKey(); int categoryCount = 0; bool imageSelected = false; + bool needsAtLeastOneCategory = false; + final Map _formData = { 'title': '', 'categories': [], @@ -30,7 +32,6 @@ class _JarPageState extends State { formKey.currentState.save(); // Save our form now. print(_formData); model.addJar(_formData); - Navigator.pop(context); } } @@ -66,6 +67,7 @@ class _JarPageState extends State { imageSelected = false; } categoryCount += 1; + needsAtLeastOneCategory = false; }); } @@ -83,14 +85,16 @@ class _JarPageState extends State { elevation: 0, actions: [ IconButton( - padding: EdgeInsets.only(right: 25), - icon: Icon(Icons.keyboard_arrow_down), - color: Theme.of(context).iconTheme.color, - iconSize: Theme.of(context).iconTheme.size, - highlightColor: Colors.transparent, - splashColor: Colors.transparent, - onPressed: () => Navigator.pop(context), - ) + padding: EdgeInsets.only(right: 25), + icon: Icon(Icons.keyboard_arrow_down), + color: Theme.of(context).iconTheme.color, + iconSize: Theme.of(context).iconTheme.size, + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + onPressed: () { + FocusScope.of(context).requestFocus(FocusNode()); + Navigator.pop(context); + }) ], ), body: Container( @@ -99,7 +103,7 @@ class _JarPageState extends State { color: Theme.of(context).primaryColor, ), child: ListView( - shrinkWrap: true, + // shrinkWrap: true, children: [ Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -108,6 +112,7 @@ class _JarPageState extends State { AddJarForm( formKey: formKey, imageSelected: imageSelected, + needsAtLeastOneCategory: needsAtLeastOneCategory, updateCategory: updateCategory, updateTitle: updateTitle, updateImage: updateImage, @@ -142,8 +147,10 @@ class _JarPageState extends State { color: Theme.of(context).secondaryHeaderColor, splashColor: Colors.transparent, highlightColor: Theme.of(context).primaryColor, - onPressed: () => addJar(model), - ) + onPressed: () { + FocusScope.of(context).requestFocus(FocusNode()); + addJar(model); + }) : CircularProgressIndicator(), ], ) diff --git a/fude_app/lib/pages/jars/jar_edit.dart b/fude_app/lib/pages/jars/jar_edit.dart index 98e4c41..6845d00 100644 --- a/fude_app/lib/pages/jars/jar_edit.dart +++ b/fude_app/lib/pages/jars/jar_edit.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'package:scoped_model/scoped_model.dart'; import 'dart:io'; @@ -10,8 +11,9 @@ import 'package:fude/widgets/forms/add_user_to_jar.dart'; class EditJarPage extends StatefulWidget { final MainModel model; + final DocumentSnapshot jar; - EditJarPage({this.model}); + EditJarPage({this.model, this.jar}); @override State createState() { return _JarPageState(); @@ -38,7 +40,8 @@ class _JarPageState extends State { @override void initState() { _waitingForJarData(); - + widget.model.getJarBySelectedId(widget.jar.documentID); + widget.model.resetIsLoading(); super.initState(); } @@ -156,14 +159,16 @@ class _JarPageState extends State { elevation: 0, actions: [ IconButton( - padding: EdgeInsets.only(right: 25), - icon: Icon(Icons.keyboard_arrow_down), - color: Theme.of(context).iconTheme.color, - iconSize: Theme.of(context).iconTheme.size, - highlightColor: Colors.transparent, - splashColor: Colors.transparent, - onPressed: () => Navigator.pop(context), - ) + padding: EdgeInsets.only(right: 25), + icon: Icon(Icons.keyboard_arrow_down), + color: Theme.of(context).iconTheme.color, + iconSize: Theme.of(context).iconTheme.size, + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + onPressed: () { + FocusScope.of(context).requestFocus(FocusNode()); + Navigator.pop(context); + }), ], ), body: Container( @@ -208,30 +213,36 @@ class _JarPageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ RaisedButton( - child: Text( - 'UPDATE JAR', - style: TextStyle( - color: Theme.of(context).primaryColor, - fontWeight: FontWeight.bold, - fontSize: 15, - letterSpacing: 5, + child: Text( + 'UPDATE JAR', + style: TextStyle( + color: Theme.of(context).primaryColor, + fontWeight: FontWeight.bold, + fontSize: 15, + letterSpacing: 5, + ), ), - ), - elevation: 7, - highlightElevation: 1, - padding: EdgeInsets.all(15), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0)), - color: Theme.of(context).secondaryHeaderColor, - splashColor: Colors.transparent, - highlightColor: Theme.of(context).primaryColor, - onPressed: () => updateJar(model), - ), + elevation: 7, + highlightElevation: 1, + padding: EdgeInsets.all(15), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(10.0)), + color: Theme.of(context).secondaryHeaderColor, + splashColor: Colors.transparent, + highlightColor: + Theme.of(context).primaryColor, + onPressed: () { + FocusScope.of(context) + .requestFocus(FocusNode()); + updateJar(model); + }), IconButton( icon: Icon(Icons.delete), iconSize: 36, color: Colors.red, onPressed: () { + FocusScope.of(context).requestFocus(FocusNode()); model.deleteJar(); Navigator.pop(context); }) @@ -243,7 +254,9 @@ class _JarPageState extends State { ], ) : Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicator( + strokeWidth: 6, + ), ), ), ); diff --git a/fude_app/lib/scoped-models/jar.dart b/fude_app/lib/scoped-models/jar.dart index 574579f..8b4ae92 100644 --- a/fude_app/lib/scoped-models/jar.dart +++ b/fude_app/lib/scoped-models/jar.dart @@ -8,8 +8,11 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_storage/firebase_storage.dart'; import 'package:url_launcher/url_launcher.dart'; import 'dart:io'; +import 'package:shared_preferences/shared_preferences.dart'; mixin JarModel on Model { + bool _isLoading = false; + bool _darkTheme = false; final FirebaseAuth _auth = FirebaseAuth.instance; final Firestore _firestore = Firestore.instance; DocumentSnapshot _selJar; @@ -22,10 +25,6 @@ mixin JarModel on Model { List _usersJars = []; List categoryChildren = []; - bool _isLoading = false; - - bool darkTheme = false; - DocumentSnapshot get selectedJar { return _selJar; } @@ -38,6 +37,10 @@ mixin JarModel on Model { return _isLoading; } + bool get darkTheme { + return _darkTheme; + } + List get usersJars { return _usersJars; } @@ -147,13 +150,16 @@ mixin JarModel on Model { } }); }); - _isLoading = false; - notifyListeners(); } catch (e) { print(e); } } + void resetIsLoading() { + _isLoading = false; + notifyListeners(); + } + void addToJar(String category, String title, String notes, String link, File image) async { print('image: ----------- $image'); @@ -292,17 +298,18 @@ mixin JarModel on Model { Future> fetchAllUserJars(String email) async { _isLoading = true; notifyListeners(); + FirebaseUser user = await _auth.currentUser(); _usersJars = [_addJar]; QuerySnapshot jars; try { jars = await _firestore .collection('jars') - .where('owners', arrayContains: email) + .where('owners', arrayContains: email != null ? email : user.email) .getDocuments(); jars.documents.forEach((jar) { _usersJars.insert(1, jar); }); - // print('NEW LIST: $_usersJars'); + print('NEW LIST: $_usersJars'); } catch (e) { print(e); } @@ -352,11 +359,29 @@ mixin JarModel on Model { } } + Future getThemeFromPrefs() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + _darkTheme = prefs.getBool('darkTheme') != null ? prefs.getBool('darkTheme') : false; + print(_darkTheme); + notifyListeners(); + return _darkTheme; + } + void invertTheme() { - darkTheme = !darkTheme; + _darkTheme = !_darkTheme; + storeThemePref(_darkTheme); notifyListeners(); } + Future storeThemePref(bool val) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + try { + await prefs.setBool('darkTheme', val); + } catch (e) { + print(e); + } + } + numberOfIdeasInCategory(String category) async { int total = 0; QuerySnapshot ideas; @@ -377,4 +402,9 @@ mixin JarModel on Model { } return total; } + + void resetUsersJars() { + _usersJars = []; + notifyListeners(); + } } diff --git a/fude_app/lib/scoped-models/user.dart b/fude_app/lib/scoped-models/user.dart index 5fe1c1a..1df98fc 100644 --- a/fude_app/lib/scoped-models/user.dart +++ b/fude_app/lib/scoped-models/user.dart @@ -4,11 +4,10 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:fude/helpers/exceptions.dart'; - mixin UserModel on Model { final FirebaseAuth _auth = FirebaseAuth.instance; FirebaseUser _currentUser; - var isLoading = false; + var _isLoading = false; var resetLinkSent = false; String _currUserEmail; FirebaseUser get currentUser { @@ -25,17 +24,17 @@ mixin UserModel on Model { } Future register({String email, String password}) async { - isLoading = true; + _isLoading = true; notifyListeners(); FirebaseUser newUser; try { newUser = await _auth.createUserWithEmailAndPassword( email: email, password: password); _currentUser = newUser; - isLoading = false; + _isLoading = false; notifyListeners(); } catch (err) { - isLoading = false; + _isLoading = false; notifyListeners(); throw new CausedException( cause: 'Firebase Auth', @@ -48,31 +47,33 @@ mixin UserModel on Model { Future fetchUser() async { print('FETCHING USER'); + _isLoading = true; + notifyListeners(); _currentUser = await _auth.currentUser(); + _isLoading = false; notifyListeners(); } Future login({String email, String password}) async { - isLoading = true; + _isLoading = true; notifyListeners(); try { FirebaseUser user = await _auth.signInWithEmailAndPassword( email: email, password: password); _currentUser = user; _currUserEmail = _currentUser.email; - print("successful login. User..."); - print(_currentUser); - isLoading = false; + print("successful login. User = $_currentUser"); + _isLoading = false; notifyListeners(); } catch (e) { - isLoading = false; + _isLoading = false; notifyListeners(); throw new CausedException( cause: 'Firebase Auth', code: "1", message: 'login error', userMessage: - "It looks like your email and password might not match. Give it another shot."); + "Check your email and password and try again."); } } diff --git a/fude_app/lib/widgets/form-inputs/input_fields.dart b/fude_app/lib/widgets/form-inputs/input_fields.dart index 681f208..6e3629e 100644 --- a/fude_app/lib/widgets/form-inputs/input_fields.dart +++ b/fude_app/lib/widgets/form-inputs/input_fields.dart @@ -26,6 +26,7 @@ class InputFieldArea extends StatelessWidget { ), ), child: TextFormField( + textCapitalization: TextCapitalization.none, obscureText: obscure, style: TextStyle( color: Theme.of(context).primaryColor, diff --git a/fude_app/lib/widgets/forms/add_jar.dart b/fude_app/lib/widgets/forms/add_jar.dart index aa50a71..d5bd7b8 100644 --- a/fude_app/lib/widgets/forms/add_jar.dart +++ b/fude_app/lib/widgets/forms/add_jar.dart @@ -10,6 +10,7 @@ class AddJarForm extends StatelessWidget { final GlobalKey formKey; final int categoryCount; final bool imageSelected; + final bool needsAtLeastOneCategory; final Function updateTitle; final Function updateCategory; final Function updateImage; @@ -22,6 +23,7 @@ class AddJarForm extends StatelessWidget { {this.formKey, this.jar, this.imageSelected, + this.needsAtLeastOneCategory, this.categoryCount, this.updateTitle, this.updateCategory, @@ -53,6 +55,7 @@ class AddJarForm extends StatelessWidget { color: Theme.of(context).iconTheme.color, onPressed: () { updateCategoryCount(); + _addCategoryInputs(); }) : Container() ], @@ -69,6 +72,7 @@ class AddJarForm extends StatelessWidget { model: model, enabled: true, categories: categories, + needsAtLeastOneCategory: needsAtLeastOneCategory ), ], ), @@ -102,11 +106,9 @@ class AddJarForm extends StatelessWidget { SizedBox(height: height * 0.035), _buildFormTitles("CATEGORIES", context), SizedBox(height: height * 0.01), - categoryCount >= 0 && !imageSelected - ? _addCategoryInputs() - : Column( - children: model.categoryChildren, - ), + Column( + children: model.categoryChildren, + ), SizedBox(height: height * 0.035), _buildFormTitles("JAR IMAGE", context), SizedBox(height: height * 0.03), diff --git a/fude_app/lib/widgets/forms/add_user_to_jar.dart b/fude_app/lib/widgets/forms/add_user_to_jar.dart index 988476c..ce16ad6 100644 --- a/fude_app/lib/widgets/forms/add_user_to_jar.dart +++ b/fude_app/lib/widgets/forms/add_user_to_jar.dart @@ -63,7 +63,7 @@ class AddUserToJarForm extends StatelessWidget { ), model.isLoading ? CircularProgressIndicator( - backgroundColor: Colors.transparent, strokeWidth: 4) + backgroundColor: Colors.transparent, strokeWidth: 5, ) : IconButton( icon: Icon(Icons.send), onPressed: () => submitAddUser(), @@ -75,7 +75,7 @@ class AddUserToJarForm extends StatelessWidget { ? Container( padding: EdgeInsets.only(left: width * 0.04), child: Text( - 'Added!', + 'Shared!', style: TextStyle( color: Theme.of(context).secondaryHeaderColor, fontSize: diff --git a/fude_app/lib/widgets/forms/edit_jar.dart b/fude_app/lib/widgets/forms/edit_jar.dart index 7eee029..c466f5b 100644 --- a/fude_app/lib/widgets/forms/edit_jar.dart +++ b/fude_app/lib/widgets/forms/edit_jar.dart @@ -55,6 +55,7 @@ class EditJarForm extends StatelessWidget { color: Theme.of(context).iconTheme.color, onPressed: () { updateCategoryCount(); + _addCategoryInputs(); }) : Container() ], @@ -138,7 +139,9 @@ class EditJarForm extends StatelessWidget { : Container(), SizedBox(height: height * 0.01), _buildExistingCategoryInputs(context), - categoryCount > 0 ? _addCategoryInputs() : Container(), + Column( + children: model.categoryChildren, + ), SizedBox(height: height * 0.035), _buildFormTitles("JAR IMAGE", context), SizedBox(height: height * 0.03), diff --git a/fude_app/lib/widgets/logo.dart b/fude_app/lib/widgets/logo.dart index d90ffd5..419758f 100644 --- a/fude_app/lib/widgets/logo.dart +++ b/fude_app/lib/widgets/logo.dart @@ -5,10 +5,12 @@ class Logo extends StatelessWidget { Logo({this.image}); @override Widget build(BuildContext context) { + final double height = MediaQuery.of(context).size.height; return Container( width: 250.0, height: 250.0, + padding: EdgeInsets.only(top: height * 0.07), alignment: Alignment.center, child: Text('JARS', style: TextStyle(