Skip to content

Commit

Permalink
profile provider added
Browse files Browse the repository at this point in the history
  • Loading branch information
Bijayanee committed Oct 13, 2024
1 parent 90a10ed commit 662c811
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hacktoberxmlsa_app/providers/userProfile.dart';
import 'package:hacktoberxmlsa_app/services/colors.dart';
import 'package:hacktoberxmlsa_app/views/homePage.dart';
import 'package:hacktoberxmlsa_app/views/splashScreen.dart';
import 'package:provider/provider.dart';

void main() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
runApp(const MyApp());
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => UserProfileProvider()),
],
child: MyApp(),
),
);
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {

Expand Down
33 changes: 33 additions & 0 deletions lib/providers/userProfile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/cupertino.dart';

class UserProfileProvider extends ChangeNotifier{

String _imageUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRnDNmpgYnTP4ELmIob69uKE1O0Rbrotna00g&s';
String _name = "MLSA";
String _email = "[email protected]";
String _roll = "12345";

String get name => _name;
String get email => _email;
String get roll => _roll;
String get image => _imageUrl;

void updateProfile(String newImage){
_imageUrl = newImage;
notifyListeners();
}
void updateName(String newName) {
_name = newName;
notifyListeners();
}

void updateEmail(String newEmail) {
_email = newEmail;
notifyListeners();
}

void updateRoll(String newRoll) {
_roll = newRoll;
notifyListeners();
}
}
39 changes: 38 additions & 1 deletion lib/views/profile.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:hacktoberxmlsa_app/providers/userProfile.dart';
import 'package:hacktoberxmlsa_app/views/homePage.dart';
import 'package:hacktoberxmlsa_app/widgets/button.dart';
import 'package:hacktoberxmlsa_app/widgets/textfield.dart';
import 'package:provider/provider.dart';

class ProfilePage extends StatefulWidget {
const ProfilePage({super.key});
Expand All @@ -17,9 +19,29 @@ class _ProfilePageState extends State<ProfilePage> {
final TextEditingController nameController= TextEditingController();
final TextEditingController rollController= TextEditingController();

String savedName = '';
String savedRoll = '';
String savedEmail = '';
String savedPassword = '';

void saveProfileDetails() {
setState(() {
savedName = nameController.text;
savedRoll = rollController.text;
savedEmail = emailController.text;
savedPassword = passwordController.text;
});

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Profile details saved successfully!')),
);
}

@override
Widget build(BuildContext context) {

final userProfile = Provider.of<UserProfileProvider>(context);

double screenWidth = MediaQuery.of(context).size.width;
double screenHeight = MediaQuery.of(context).size.height;

Expand Down Expand Up @@ -91,6 +113,9 @@ class _ProfilePageState extends State<ProfilePage> {
SizedBox(height: screenHeight*0.004,),
CustomTextField(
controller: nameController,
onChanged: (value) {
userProfile.updateName(value);
}
),
SizedBox(height: screenHeight*0.02,),
Text(
Expand All @@ -102,6 +127,9 @@ class _ProfilePageState extends State<ProfilePage> {
SizedBox(height: screenHeight*0.004,),
CustomTextField(
controller: rollController,
onChanged: (value) {
userProfile.updateRoll(value);
},
),
SizedBox(height: screenHeight*0.02,),
Text(
Expand All @@ -113,6 +141,9 @@ class _ProfilePageState extends State<ProfilePage> {
SizedBox(height: screenHeight*0.004,),
CustomTextField(
controller: emailController,
onChanged: (value) {
userProfile.updateEmail(value);
},
),
SizedBox(height: screenHeight*0.02,),
Text(
Expand All @@ -126,7 +157,13 @@ class _ProfilePageState extends State<ProfilePage> {
controller: passwordController,
),
SizedBox(height: screenHeight*0.04,),
CustomButton(onPressed: () {}, text: "Save"),
CustomButton(
onPressed: () {
saveProfileDetails;
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomePage()));
},
text: "Save"
),
],
),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import 'package:flutter/material.dart';
class CustomTextField extends StatelessWidget {
final TextEditingController controller;
//final String hintText;
final Function(String)? onChanged;

const CustomTextField({
Key? key,
required this.controller,
//required this.hintText,
this.onChanged,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
onChanged: onChanged,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
Expand Down
17 changes: 17 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
Expand All @@ -139,6 +147,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
provider:
dependency: "direct main"
description:
name: provider
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
url: "https://pub.dev"
source: hosted
version: "6.1.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -210,3 +226,4 @@ packages:
version: "13.0.0"
sdks:
dart: ">=3.2.6 <4.0.0"
flutter: ">=1.16.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
provider: ^6.1.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 662c811

Please sign in to comment.