fix profile

This commit is contained in:
Sai Naw Wun
2020-10-11 02:17:23 +06:30
parent b0ce53f856
commit 32e6be2abd
42 changed files with 938 additions and 626 deletions

View File

@@ -0,0 +1,129 @@
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:fcs/pages/main/util.dart';
typedef void ProfileCallback();
enum Currency { USD, MMK }
class ProfileCurrencyEdit extends StatefulWidget {
@override
_ProfileCurrencyEditState createState() => _ProfileCurrencyEditState();
}
class _ProfileCurrencyEditState extends State<ProfileCurrencyEdit> {
final TextEditingController nameController = new TextEditingController();
bool _loading = false;
@override
void initState() {
super.initState();
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
if (mainModel.user.preferCurrency == "MMK") {
_currency = Currency.MMK;
} else {
_currency = Currency.USD;
}
}
Currency _currency = Currency.USD;
@override
Widget build(BuildContext context) {
final saveBtn =
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
return LocalProgress(
inAsyncCall: _loading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: LocalText(
context,
"profile.edit.currency.title",
fontSize: 20,
color: primaryColor,
),
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
leading: IconButton(
icon: Icon(
CupertinoIcons.back,
size: 35,
color: primaryColor,
),
onPressed: () => Navigator.of(context).pop(),
),
),
body: Column(
children: <Widget>[
InkWell(
onTap: () => setState(() {
_currency = Currency.USD;
}),
child: ListTile(
title: Text('USD'),
leading: Radio(
activeColor: primaryColor,
value: Currency.USD,
groupValue: _currency,
onChanged: (Currency value) {
setState(() {
_currency = value;
});
},
),
),
),
InkWell(
onTap: () => setState(() {
_currency = Currency.MMK;
}),
child: ListTile(
title: const Text('MMK'),
leading: Radio(
activeColor: primaryColor,
value: Currency.MMK,
groupValue: _currency,
onChanged: (Currency value) {
setState(() {
_currency = value;
});
},
),
),
),
Padding(
padding: const EdgeInsets.all(18.0),
child: saveBtn,
),
],
),
),
);
}
_save() async {
setState(() {
_loading = true;
});
try {
await Provider.of<MainModel>(context, listen: false)
.updatePreferredCurrency(_currency.toString().split(".").last);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_loading = false;
});
}
}
}

View File

@@ -96,7 +96,7 @@ class _ProfileEditState extends State<ProfileEdit> {
});
try {
await Provider.of<MainModel>(context, listen: false)
.updateProfile(nameController.text);
.updateProfileName(nameController.text);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -1,21 +1,25 @@
import 'package:fcs/domain/entities/role.dart';
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/domain/vo/privilege.dart';
import 'package:fcs/localization/transalation.dart';
import 'package:fcs/pages/delivery_address/delivery_address_list.dart';
import 'package:fcs/pages/delivery_address/delivery_address_row.dart';
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/profile/profile_currency_edit.dart';
import 'package:fcs/pages/profile/profile_edit.dart';
import 'package:fcs/pages/staff/model/staff_model.dart';
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:provider/provider.dart';
import '../../helpers/theme.dart';
@@ -33,8 +37,6 @@ class _ProfileState extends State<Profile> {
String selectedLanguage;
TextEditingController bizNameController = new TextEditingController();
DeliveryAddress _deliveryAddress = new DeliveryAddress();
static final List<String> languagesList = Translation().supportedLanguages;
static final List<String> languageCodesList =
Translation().supportedLanguagesCodes;
@@ -56,12 +58,6 @@ class _ProfileState extends State<Profile> {
@override
void initState() {
super.initState();
var shipmentModel =
Provider.of<DeliveryAddressModel>(context, listen: false);
if (shipmentModel.deliveryAddresses.length != 0) {
_deliveryAddress = shipmentModel.deliveryAddresses[0];
}
}
@override
@@ -70,11 +66,19 @@ class _ProfileState extends State<Profile> {
if (mainModel.user == null) {
return Container();
}
DeliveryAddressModel deliveryAddressModel =
Provider.of<DeliveryAddressModel>(context);
final namebox = DisplayText(
text: mainModel.user.name,
text: mainModel.user.name + " (${mainModel.user.status})",
labelTextKey: "profile.name",
iconData: Icons.person,
);
final currencyBox = DisplayText(
text: mainModel.user.preferCurrency,
labelTextKey: "profile.currency",
iconData: FontAwesome5.money_bill_alt,
);
final phonenumberbox = DisplayText(
text: mainModel.user.phone,
@@ -142,42 +146,40 @@ class _ProfileState extends State<Profile> {
),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
actions: <Widget>[],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
child: ListView(
children: <Widget>[
Expanded(
child: ListView(
shrinkWrap: true,
children: <Widget>[
Row(
children: <Widget>[
Expanded(child: namebox),
Padding(
padding: const EdgeInsets.only(right: 0),
child: IconButton(
icon: Icon(Icons.edit, color: Colors.grey),
onPressed: _editName),
)
],
),
mainModel.isCustomer()
? Container()
: getPrivilegeBox(context),
getShippingAddressList(context),
phonenumberbox,
fcsIDBox,
usaShippingAddressBox,
DisplayText(
text: mainModel.user.status,
labelTextKey: "customer.status",
iconData: Icons.add_alarm,
),
],
),
Row(
children: <Widget>[
Expanded(child: namebox),
Padding(
padding: const EdgeInsets.only(right: 0),
child: IconButton(
icon: Icon(Icons.edit, color: Colors.grey),
onPressed: _editName),
)
],
),
phonenumberbox,
fcsIDBox,
usaShippingAddressBox,
Row(
children: <Widget>[
Expanded(child: currencyBox),
Padding(
padding: const EdgeInsets.only(right: 0),
child: IconButton(
icon: Icon(Icons.edit, color: Colors.grey),
onPressed: _editCurrency),
)
],
),
defalutDeliveryAddress(
context, deliveryAddressModel.defalutAddress),
getPrivilegeBox(context),
SizedBox(height: 15),
logoutbutton,
SizedBox(height: 25)
],
@@ -187,221 +189,104 @@ class _ProfileState extends State<Profile> {
);
}
Widget getShippingAddressList(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
return ListTileTheme(
contentPadding: EdgeInsets.all(10),
child: ExpansionTile(
title: Text(
getLocalString(context, 'delivery_addresses'),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
)
: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "Myanmar3"),
),
children: <Widget>[
showDeliveryAddress(_deliveryAddress),
Container(
padding: EdgeInsets.only(top: 20, bottom: 15, right: 15),
child: Align(
alignment: Alignment.bottomRight,
child: Container(
width: 130,
height: 40,
child: FloatingActionButton.extended(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () async {
DeliveryAddress deliveryAddress = await Navigator.push(
context,
BottomUpPageRoute(DeliveryAddressList(
deliveryAddress: _deliveryAddress)),
);
setState(() {
_deliveryAddress = deliveryAddress;
});
},
label: LocalText(context,
'delivery_address.change_address',
fontSize: 12,
color: Colors.white,
),
backgroundColor: primaryColor,
),
Widget defalutDeliveryAddress(
BuildContext context, DeliveryAddress deliveryAddress) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: DisplayText(
labelTextKey: "delivery_address",
iconData: MaterialCommunityIcons.truck_fast,
),
),
)
],
),
);
}
Widget showDeliveryAddress(DeliveryAddress deliveryAddress) {
return Container(
padding: EdgeInsets.only(left: 10, right: 10),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Row(
children: <Widget>[
new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.fullName == null
? ''
: deliveryAddress.fullName,
style: new TextStyle(
fontSize: 15.0,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.addressLine1 == null
? ''
: deliveryAddress.addressLine1,
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.addressLine2 == null
? ''
: deliveryAddress.addressLine2,
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.city == null
? ''
: deliveryAddress.city,
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.state == null
? ''
: deliveryAddress.state,
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.country == null
? ''
: deliveryAddress.country,
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
deliveryAddress.phoneNumber == null
? ''
: "Phone:${deliveryAddress.phoneNumber}",
style: new TextStyle(
fontSize: 14.0, color: Colors.grey),
),
),
],
),
],
),
),
Chip(
label: InkWell(
onTap: () => Navigator.push(
context,
BottomUpPageRoute(DeliveryAddressList()),
),
],
),
],
),
child: LocalText(context, "delivery_address.change_address",
color: primaryColor),
))
],
),
Padding(
padding: const EdgeInsets.only(left: 28.0),
child: deliveryAddress == null
? Container()
: DeliveryAddressRow(
key: ValueKey(deliveryAddress.id),
deliveryAddress: deliveryAddress),
),
],
);
}
List<Privilege> privileges = [
Privilege(name: 'Manage shipment'),
Privilege(name: 'Manage pickups'),
Privilege(name: 'Manage packages'),
Privilege(name: 'Manage deliveries'),
Privilege(name: 'Admin')
];
Widget getPrivilegeBox(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
User user = Provider.of<MainModel>(context, listen: false).user;
List<Privilege> _privileges =
Provider.of<StaffModel>(context, listen: false).privileges;
return ListTileTheme(
contentPadding: EdgeInsets.all(10),
child: ExpansionTile(
title: Text(
AppTranslations.of(context).text("profile.privilege"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
)
: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "Myanmar3"),
if (user == null || user.isCustomer()) return Container();
List<Privilege> privileges = [];
user.privileges.forEach((e) {
var p = _privileges.firstWhere((p) => p.id == e, orElse: () => null);
if (p != null) {
privileges.add(p);
}
});
return Column(
children: <Widget>[
DisplayText(
labelTextKey: "profile.privileges",
iconData: MaterialCommunityIcons.clipboard_check_outline,
),
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: getRowPrivilegeWidget(privileges)),
),
)
],
),
Padding(
padding: const EdgeInsets.only(left: 30.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: getRowPrivilegeWidget(privileges)),
)
],
);
}
List<Widget> getRowPrivilegeWidget(List<Privilege> privileges) {
return privileges.map((p) {
return Container(
padding: EdgeInsets.all(8.0),
padding: EdgeInsets.all(3.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(p.name,
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal)),
SizedBox(
width: 30,
Icon(
p.iconData,
color: Colors.black38,
),
Container(
child: Text(
"- ${p.desc}",
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
SizedBox(
width: 10,
),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("${p.name}",
style: TextStyle(
fontSize: 16.0,
fontStyle: FontStyle.normal,
color: primaryColor,
)),
Text(
"${p.desc}",
style: TextStyle(
fontSize: 14.0,
fontStyle: FontStyle.normal,
color: Colors.black38),
),
],
),
)
],
@@ -415,7 +300,7 @@ class _ProfileState extends State<Profile> {
_showToast(title);
}
void _showToast(String title) {
_showToast(String title) {
final ScaffoldState scaffold = key.currentState;
scaffold.showSnackBar(
SnackBar(
@@ -431,6 +316,11 @@ class _ProfileState extends State<Profile> {
.push<void>(CupertinoPageRoute(builder: (context) => ProfileEdit()));
}
_editCurrency() {
Navigator.of(context).push<void>(
CupertinoPageRoute(builder: (context) => ProfileCurrencyEdit()));
}
_logout() {
showConfirmDialog(context, "profile.logout.confirm", () async {
setState(() {