From dcb166ac395063436a50666c28e16dfd997902e7 Mon Sep 17 00:00:00 2001 From: Nghia Nguyen Date: Sun, 26 Feb 2023 23:23:53 -0500 Subject: [PATCH 1/2] editable profile --- app/lib/models/userModel.dart | 25 +++++++++ app/lib/screens/EditProfile.dart | 68 ++++++++++++++++++++++++ app/lib/screens/ProfileScreen.dart | 85 +++++++++++++++++++++--------- 3 files changed, 153 insertions(+), 25 deletions(-) create mode 100644 app/lib/models/userModel.dart create mode 100644 app/lib/screens/EditProfile.dart diff --git a/app/lib/models/userModel.dart b/app/lib/models/userModel.dart new file mode 100644 index 0000000..d634a0f --- /dev/null +++ b/app/lib/models/userModel.dart @@ -0,0 +1,25 @@ +class User { + String name; + String about; + String imagePath; + //final List progress; + + //save user data + //get user data + + User({required this.name, required this.about, required this.imagePath}); + + void saveData() {} + void writeData() {} + void loadData() {} +} + +class UserPreferences { + static User myUser = User( + name: "Lorem Ipsum", + about: "BIO: This is where the profile would be. " + "This is would hold the users information as well as the settings area of the app. " + "This would keep statistics such as your streaks and could even show proficiencies", + imagePath: + "https://static.vecteezy.com/system/resources/thumbnails/003/337/584/small/default-avatar-photo-placeholder-profile-icon-vector.jpg"); +} diff --git a/app/lib/screens/EditProfile.dart b/app/lib/screens/EditProfile.dart new file mode 100644 index 0000000..3de6020 --- /dev/null +++ b/app/lib/screens/EditProfile.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; +import 'package:pohnpeian_language_app/models/userModel.dart'; +import 'package:pohnpeian_language_app/theme/style.dart' as style; + +class EditProfilePage extends StatefulWidget { + @override + _EditProfilePageState createState() => _EditProfilePageState(); +} + +class _EditProfilePageState extends State { + TextEditingController nameController = TextEditingController(); + TextEditingController aboutController = TextEditingController(); + User user = UserPreferences.myUser; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Profile"), + backgroundColor: const Color.fromARGB(255, 117, 178, 221), + ), + body: ListView( + children: [ + Container( + margin: const EdgeInsets.all(30), + child: TextFormField( + controller: nameController, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: 'User Name', + labelStyle: TextStyle(color: Colors.black), + ))), + Container( + margin: const EdgeInsets.fromLTRB(30, 0, 30, 30), + child: TextFormField( + keyboardType: TextInputType.multiline, + maxLines: 7, + controller: aboutController, + decoration: const InputDecoration( + alignLabelWithHint: true, + border: OutlineInputBorder(), + labelText: 'About Me', + labelStyle: TextStyle( + color: Colors.black, + ), + ))), + Container( + margin: const EdgeInsets.fromLTRB(30, 0, 30, 0), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: style.secondary, + ), + child: const Text('Submit Changes'), + onPressed: () { + // state conditions for changing name + if (nameController.text != "") { + UserPreferences.myUser.name = nameController.text; + } + UserPreferences.myUser.about = aboutController.text; + UserPreferences.myUser.saveData(); + Navigator.pop(context); + }, + )) + ], + ), + ); + } +} diff --git a/app/lib/screens/ProfileScreen.dart b/app/lib/screens/ProfileScreen.dart index e0bc5b0..00d29c5 100644 --- a/app/lib/screens/ProfileScreen.dart +++ b/app/lib/screens/ProfileScreen.dart @@ -1,5 +1,8 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; +import 'package:pohnpeian_language_app/models/userModel.dart' as usermodel; +import 'package:pohnpeian_language_app/theme/style.dart' as style; +import 'package:pohnpeian_language_app/screens/EditProfile.dart'; class ProfileScreen extends StatefulWidget { const ProfileScreen({super.key}); @@ -11,39 +14,71 @@ class ProfileScreen extends StatefulWidget { class _ProfileScreenState extends State { @override Widget build(BuildContext context) { + usermodel.UserPreferences.myUser.loadData(); return Scaffold( // ignore: prefer_const_constructors - appBar: AppBar(title: Text("Profile"), - backgroundColor: Color.fromARGB(255, 117, 178, 221), - - ), - body: Column( - mainAxisAlignment: MainAxisAlignment.center, + appBar: AppBar( + automaticallyImplyLeading: false, + title: Text("Profile"), + backgroundColor: Color.fromARGB(255, 117, 178, 221), + ), + body: ListView( children: [ Container( - height: 60, - width: 60, - child: CircleAvatar( - backgroundImage: NetworkImage( - "https://static.vecteezy.com/system/resources/thumbnails/003/337/584/small/default-avatar-photo-placeholder-profile-icon-vector.jpg"))), - Text("USERNAME"), + margin: EdgeInsets.fromLTRB(0, 40, 0, 30), + child: Center( + child: Stack(children: [ + SizedBox( + height: 120, + width: 120, + child: CircleAvatar( + backgroundImage: NetworkImage( + usermodel.UserPreferences.myUser.imagePath))), + Positioned( + bottom: 0, + right: 4, + child: ClipOval( + child: Material( + color: style.secondary, // Button color + child: InkWell( + splashColor: style.primary, + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => EditProfilePage(), + )) + .then((_) => setState( + () {})), // .then allows for the page to refresh + child: const SizedBox( + height: 40, + width: 40, + child: Icon( + Icons.edit, + color: Colors.white, + ))), + ), + )) + ]))), + Center( + child: Text( + usermodel.UserPreferences.myUser.name, + style: TextStyle(fontSize: 20), + )), Container( margin: EdgeInsets.all(30), // ignore: prefer_const_constructors - child: Text( - "BIO: This is where the profile would be. " - "This is would hold the users information as well as the settings area of the app. " - "This would keep statistics such as your streaks and could even show proficiencies.") ), - TextButton(onPressed: () { - final docUser = FirebaseFirestore.instance - .collection('Users') - .doc('userBase'); - - docUser.set({ - 'name': '', - }); + child: Text(usermodel.UserPreferences.myUser.about)), + TextButton( + onPressed: () { + final docUser = FirebaseFirestore.instance + .collection('Users') + .doc('userBase'); - }, child: Text(" Delete Account ")), + docUser.set({ + 'name': '', + }); + }, + child: Text(" Delete Account ")), ], )); } From f18e365ff3ba096b669f3ff9aaf0a6fe441508b8 Mon Sep 17 00:00:00 2001 From: Nghia Nguyen Date: Mon, 27 Feb 2023 01:46:18 -0500 Subject: [PATCH 2/2] Update userModel.dart --- app/lib/models/userModel.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/app/lib/models/userModel.dart b/app/lib/models/userModel.dart index d634a0f..53f37b6 100644 --- a/app/lib/models/userModel.dart +++ b/app/lib/models/userModel.dart @@ -10,7 +10,6 @@ class User { User({required this.name, required this.about, required this.imagePath}); void saveData() {} - void writeData() {} void loadData() {} }