diff --git a/fude_app/lib/pages/home/home.dart b/fude_app/lib/pages/home/home.dart index 6ec347b..871c9c4 100644 --- a/fude_app/lib/pages/home/home.dart +++ b/fude_app/lib/pages/home/home.dart @@ -20,7 +20,6 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { @override initState() { - print('home init state. CurrUserEmail: ${widget.model.currUserEmail}'); widget.model.fetchAllUserJars(widget.model.currUserEmail); super.initState(); } diff --git a/fude_app/lib/pages/home/home_page_jar.dart b/fude_app/lib/pages/home/home_page_jar.dart index 268e249..248169c 100644 --- a/fude_app/lib/pages/home/home_page_jar.dart +++ b/fude_app/lib/pages/home/home_page_jar.dart @@ -75,7 +75,7 @@ class HomePageJar extends StatelessWidget { iconSize: 26, color: Theme.of(context).textTheme.subhead.color, onPressed: () { - print('jar pressed, ${jar['id']}'); + // print('jar pressed, ${jar['id']}'); model.getJarBySelectedId(jar.documentID); Navigator.push( context, @@ -126,19 +126,20 @@ class HomePageJar extends StatelessWidget { @override Widget build(BuildContext context) { + Image jarImage = Image( + image: NetworkImage(jar != null + ? jar.data['image'] + : 'https://firebasestorage.googleapis.com/v0/b/fude-app.appspot.com/o/Scoot-01.png?alt=media&token=53fc26de-7c61-4076-a0cb-f75487779604'), + fit: BoxFit.cover, + alignment: FractionalOffset( + 0.5, + 0.5, + ), + ); var image = title == null ? ClipRRect( borderRadius: BorderRadius.circular(30.0), - child: Image.network( - jar['image'] != null - ? jar['image'] - : 'https://firebasestorage.googleapis.com/v0/b/fude-app.appspot.com/o/Scoot-01.png?alt=media&token=53fc26de-7c61-4076-a0cb-f75487779604', - fit: BoxFit.cover, - alignment: FractionalOffset( - 0.5, - 0.5, - ), - ), + child: jarImage, ) : Container(); diff --git a/fude_app/lib/pages/jars/jar_add.dart b/fude_app/lib/pages/jars/jar_add.dart index b3dfc17..b692e04 100644 --- a/fude_app/lib/pages/jars/jar_add.dart +++ b/fude_app/lib/pages/jars/jar_add.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:scoped_model/scoped_model.dart'; import 'dart:io'; @@ -29,7 +31,7 @@ class _JarPageState extends State { formKey.currentState.save(); // Save our form now. print(_formData); model.addJar(_formData); - model.fetchAllUserJars(model.currUserEmail); + Navigator.pop(context); } } @@ -116,26 +118,28 @@ class _JarPageState extends State { SizedBox( width: width * 0.055, ), - RaisedButton( - child: Text( - 'ADD 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: () => addJar(model), - ), + !model.isLoading + ? RaisedButton( + child: Text( + 'ADD 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: () => addJar(model), + ) + : CircularProgressIndicator(), ], ) ], diff --git a/fude_app/lib/pages/jars/jar_edit.dart b/fude_app/lib/pages/jars/jar_edit.dart index 619c6cf..e903bfe 100644 --- a/fude_app/lib/pages/jars/jar_edit.dart +++ b/fude_app/lib/pages/jars/jar_edit.dart @@ -235,7 +235,6 @@ class _JarPageState extends State { onPressed: () { model.deleteJar(); model.fetchAllUserJars(model.currUserEmail); - Navigator.pop(context); }) ], diff --git a/fude_app/lib/scoped-models/jar.dart b/fude_app/lib/scoped-models/jar.dart index 5e1aac4..a337cec 100644 --- a/fude_app/lib/scoped-models/jar.dart +++ b/fude_app/lib/scoped-models/jar.dart @@ -43,8 +43,11 @@ mixin JarModel on Model { void addJar(Map data) async { print('in model.addJar: data: $data'); + _isLoading = true; + notifyListeners(); + CollectionReference jarCollection = _firestore.collection('jars'); - Uri imageLocation; + String imageLocation; try { if (data['image'] != null) { imageLocation = await uploadNoteImageToStorage(data['image']); @@ -59,6 +62,8 @@ mixin JarModel on Model { : imageLocation.toString(), 'isFav': false }); + fetchAllUserJars(user.email); + _isLoading = false; notifyListeners(); } catch (e) { print(e); @@ -67,7 +72,7 @@ mixin JarModel on Model { void updateJar(Map data) async { print('updateJar Data: $data'); - Uri imageLocation; + String imageLocation; try { if (data['image'] != null) { imageLocation = await uploadNoteImageToStorage(data['image']); @@ -146,7 +151,7 @@ mixin JarModel on Model { void addToJar(String category, String title, String notes, String link, File image) async { print('image: ----------- $image'); - Uri imageLocation; + String imageLocation; try { if (image != null) { imageLocation = await uploadNoteImageToStorage(image); @@ -165,33 +170,39 @@ mixin JarModel on Model { 'image': imageLocation == null ? _selJar['image'] : imageLocation.toString(), }); + notifyListeners(); } catch (e) { print(e); } } - Future uploadNoteImageToStorage(File image) async { + Future uploadNoteImageToStorage(File image) async { final StorageReference ref = FirebaseStorage.instance.ref().child('images/'); //Upload the file to firebase StorageUploadTask uploadTask = ref.putFile(image); // Waits till the file is uploaded then stores the download url - Uri location = await uploadTask.onComplete.then((val) { - val.ref.getDownloadURL().then((val) { - print(val); - return val; //Val here is Already String + String location; + try { + await uploadTask.onComplete.then((val) async { + await val.ref.getDownloadURL().then((val) { + // print('VAL $val, type: ${val.runtimeType}'); + location = val; + }); }); - }); + } catch (e) { + print(e); + } + // print('location: $location -------'); //returns the download url - print(location); return location; } void updateNote(DocumentSnapshot note, String category, String title, String notes, String link, File image) async { print('$category, $title, $notes, $link, $image'); - Uri imageLocation; + String imageLocation; try { if (image != null) { imageLocation = await uploadNoteImageToStorage(image); @@ -256,8 +267,10 @@ mixin JarModel on Model { await _firestore .collection('jars') .document(_selJar.documentID) - .updateData({'owners' : - !_selJar.data['owners'].contains(email) ? FieldValue.arrayUnion([email]): FieldValue.arrayUnion([]) + .updateData({ + 'owners': !_selJar.data['owners'].contains(email) + ? FieldValue.arrayUnion([email]) + : FieldValue.arrayUnion([]) }); } catch (e) { print(e); @@ -272,6 +285,8 @@ mixin JarModel on Model { } Future> fetchAllUserJars(String email) async { + _isLoading = true; + notifyListeners(); _usersJars = [_addJar]; QuerySnapshot jars; try { @@ -282,11 +297,12 @@ mixin JarModel on Model { jars.documents.forEach((jar) { _usersJars.insert(1, jar); }); - print('NEW LIST: $_usersJars'); - notifyListeners(); + // print('NEW LIST: $_usersJars'); } catch (e) { print(e); } + _isLoading = false; + notifyListeners(); return _usersJars; }