You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_customer_app/lib/pages/dashboard/dashboard_page.dart

211 lines
6.1 KiB
Dart

import 'package:car_customer_app/api/shared_prefrence.dart';
import 'package:car_customer_app/config/routes.dart';
import 'package:car_customer_app/theme/colors.dart';
import 'package:car_customer_app/utils/navigator.dart';
import 'package:car_customer_app/widgets/app_bar.dart';
import 'package:car_customer_app/widgets/show_fill_button.dart';
import 'package:car_customer_app/extensions/int_extensions.dart';
import 'package:car_customer_app/extensions/string_extensions.dart';
import 'package:car_customer_app/extensions/widget_extensions.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
class DashboardPage extends StatefulWidget {
@override
State<DashboardPage> createState() => _DashboardPageState();
}
class _DashboardPageState extends State<DashboardPage> {
String userName = "";
File? imagePicked;
final _picker = ImagePicker();
@override
void initState() {
// TODO: implement initState
super.initState();
fetchUsername();
}
fetchUsername() async {
userName = await SharedPrefManager.getPhoneOrEmail();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar(
title: "Logo/Brand",
),
drawer: showDrawer(context),
body: Container(
child: Center(
child: "Dashboard/Main Page".toText24(),
),
),
);
}
Widget showDrawer(BuildContext context) {
return Drawer(
child: Container(
child: Column(
children: [
Stack(
children:[
Container(
width: double.infinity,
height: 200,
color: accentColor.withOpacity(0.3),
child: Icon(
Icons.person,
size: 80,
color: accentColor.withOpacity(0.3),
),
),
Positioned(
top: 10,
right: 10,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
),
child: Icon(Icons.edit,
color: Colors.blue,).onPress(() {
_openImagePicker();
}),
),
],
),
)
] ),
Container(
width: double.infinity,
color: accentColor.withOpacity(0.1),
padding: EdgeInsets.all(20),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
userName.toText24(),
"User role or title".toText12(),
],
),
),
ShowFillButton(
title: "EDIT",
onPressed: () {
},
),
],
),
),
ListTile(
leading: Icon(Icons.notifications),
title: "Notifications".toText12(),
),
ListTile(
leading: Icon(Icons.settings),
title: "General".toText12(),
),
ListTile(
leading: Icon(Icons.person),
title: "Account".toText12(),
),
ListTile(
leading: Icon(Icons.password),
title: "Change Password".toText12(),
onTap: () {
navigateWithName(context, AppRoutes.changePasswordPage);
},
),
ListTile(
leading: Icon(Icons.phone_android_sharp),
title: "Change Mobile".toText12(),
onTap: () {
navigateWithName(context, AppRoutes.changeMobilePage);
},
),
ListTile(
leading: Icon(Icons.email_outlined),
title: "Change Email".toText12(),
onTap: () {
navigateWithName(context, AppRoutes.changeEmailPage);
},
),
ListTile(
leading: Icon(Icons.logout),
title: "Sign Out".toText12(),
onTap: () {
pop(context);
pop(context);
},
),
],
),
),
);
}
void _openImagePicker() {
showDialog<ImageSource>(
context: context,
builder: (context) => AlertDialog(
content: Text("Choose image source"),
actions: [
FlatButton(
child: Text("Camera"),
onPressed: () =>
cameraImage()
),
FlatButton(
child: Text("Gallery"),
onPressed: () => gallaryImage()
),
]
),
// .then((ImageSource source) async {
// if (source != null) {
// final pickedFile = await ImagePicker().getImage(source: source);
// setState(() => imagePicked = File(pickedFile.path));
// }
// }
);
}
void gallaryImage() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(
source: ImageSource.gallery,
);
final pickedImageFile = File(pickedImage!.path);
setState(() {
imagePicked = pickedImageFile;
});
}
void cameraImage() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(
source: ImageSource.camera,
);
final pickedImageFile = File(pickedImage!.path);
setState(() {
imagePicked = pickedImageFile;
});
}
}