Files
fcs/lib/pages/profile_page.dart

470 lines
15 KiB
Dart
Raw Normal View History

2020-06-24 16:06:40 +06:30
import 'package:fcs/model/shipment_model.dart';
import 'package:fcs/vo/shipping_address.dart';
import 'package:fcs/widget/bottom_up_page_route.dart';
import 'package:fcs/widget/local_text.dart';
import 'package:fcs/widget/my_data_table.dart';
2020-05-29 07:45:27 +06:30
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'package:fcs/model/language_model.dart';
import 'package:fcs/model/main_model.dart';
import 'package:fcs/model/user_model.dart';
import 'package:fcs/pages/profile_edit.dart';
import 'package:fcs/pages/util.dart';
import 'package:fcs/vo/role.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/localization/transalation.dart';
import 'package:fcs/widget/progress.dart';
import '../theme/theme.dart';
import 'profile_setting.dart';
2020-06-24 16:06:40 +06:30
import 'shipping_address_editor.dart';
2020-05-29 07:45:27 +06:30
typedef void ProfileCallback();
class Profile extends StatefulWidget {
@override
_ProfileState createState() => _ProfileState();
}
class _ProfileState extends State<Profile> {
bool _isLoading = false;
String selectedLanguage;
TextEditingController bizNameController = new TextEditingController();
static final List<String> languagesList = Translation().supportedLanguages;
static final List<String> languageCodesList =
Translation().supportedLanguagesCodes;
final Map<dynamic, dynamic> languagesMap = {
languagesList[0]: languageCodesList[0],
languagesList[1]: languageCodesList[1],
};
buildLanguage(LanguageModel languageModel) async {
var lan = await languageModel.load();
if (this.selectedLanguage != lan) {
setState(() {
this.selectedLanguage = lan;
});
}
}
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
MainModel mainModel = Provider.of<MainModel>(context);
2020-06-24 16:06:40 +06:30
// buildLanguage(languageModel);
2020-05-29 07:45:27 +06:30
_selectedDropdown(String selected) {
setState(() {
selectedLanguage = selected;
languageModel.saveLanguage(selectedLanguage);
});
}
final namebox = Container(
2020-06-24 16:06:40 +06:30
// padding: EdgeInsets.only(left: 25.0, right: 25.0),
padding: EdgeInsets.only(top: 10, left: 25.0, right: 25.0),
2020-05-29 07:45:27 +06:30
child: Container(
height: 45.0,
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 0.0),
child: Text(
AppTranslations.of(context).text("profile.name"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal)
: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "MyanmarUnicode"),
),
),
SizedBox(
width: 30,
),
Container(
child: Center(
child: Text(
mainModel.user == null ? "" : mainModel.user.name,
style:
TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
),
),
)
],
),
));
2020-06-24 16:06:40 +06:30
2020-05-29 07:45:27 +06:30
final phonenumberbox = Container(
2020-06-24 16:06:40 +06:30
padding: EdgeInsets.only(left: 25.0, right: 25.0),
2020-05-29 07:45:27 +06:30
height: 45.0,
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 0.0),
child: Text(
AppTranslations.of(context).text("profile.phone"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal)
: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "MyanmarUnicode"),
),
),
SizedBox(
width: 27,
),
Container(
child: Center(
child: Text(
mainModel.user == null
? ""
: mainModel.user.phone == null ? '' : mainModel.user.phone,
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
),
),
)
],
),
);
final emailBox = Container(
2020-06-24 16:06:40 +06:30
padding: EdgeInsets.only(top: 10, left: 25.0, right: 25.0),
2020-05-29 07:45:27 +06:30
child: Row(
children: <Widget>[
Text(
AppTranslations.of(context).text("profile.email"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal)
: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "MyanmarUnicode"),
),
SizedBox(
width: 35,
),
Text(
mainModel.user == null
? ""
: mainModel.user.email == null || mainModel.user.email == ''
? ''
: mainModel.user.email,
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
),
],
),
);
final languageBox = Container(
2020-06-24 16:06:40 +06:30
padding: EdgeInsets.only(bottom: 0, top: 7, left: 25.0, right: 25.0),
2020-05-29 07:45:27 +06:30
child: Container(
height: 45.0,
child: Row(
children: <Widget>[
Text(
AppTranslations.of(context).text("profile.language"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal)
: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "MyanmarUnicode"),
),
Container(
width: 140,
padding: EdgeInsets.only(left: 30),
child: Theme(
data: new ThemeData(
canvasColor: Colors.white,
),
child: DropdownButton(
hint: Text("English"),
value: selectedLanguage,
isExpanded: true,
iconSize: 40,
items: languagesList
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: _selectedDropdown),
)),
],
),
));
final logoutbutton = Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Card(
elevation: 23,
child: Container(
height: 45.0,
child: ButtonTheme(
minWidth: 900.0,
height: 100.0,
child: FlatButton.icon(
onPressed: () {
showConfirmDialog(context, "profile.logout.confirm",
() async {
setState(() {
_isLoading = true;
});
await mainModel.logout();
2020-06-24 16:06:40 +06:30
Navigator.of(context).pushNamedAndRemoveUntil(
"/home", ModalRoute.withName('/home'));
2020-05-29 07:45:27 +06:30
Future.delayed(Duration(seconds: 1), () {
if (mounted) {
setState(() {
_isLoading = false;
});
}
});
});
},
label: Text(AppTranslations.of(context).text("profile.logout"),
style: languageModel.isEng
? TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal)
: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontFamily: "MyanmarUnicode")),
icon: Icon(
Icons.exit_to_app,
),
),
),
),
));
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
title: Text(
AppTranslations.of(context).text("profile.title"),
),
backgroundColor: primaryColor,
2020-06-24 16:06:40 +06:30
actions: <Widget>[],
2020-05-29 07:45:27 +06:30
),
body: ListView(
2020-06-24 16:06:40 +06:30
// padding: EdgeInsets.only(left: 25.0, right: 25.0),
2020-05-29 07:45:27 +06:30
shrinkWrap: true,
children: <Widget>[
2020-06-02 00:00:05 +06:30
Row(
children: <Widget>[
namebox,
Padding(
2020-06-24 16:06:40 +06:30
padding: const EdgeInsets.only(left: 18.0),
2020-06-02 00:00:05 +06:30
child: Icon(Icons.edit),
)
],
),
2020-05-29 07:45:27 +06:30
mainModel.isBuyer() ? Container() : getPrivilegeBox(context),
phonenumberbox,
mainModel.user == null
? Container()
: mainModel.user.email == null || mainModel.user.email == ''
? Container()
: emailBox,
languageBox,
2020-06-24 16:06:40 +06:30
getShippingAddressList(context),
SizedBox(
height: 50,
),
2020-05-29 07:45:27 +06:30
logoutbutton,
],
),
),
);
}
2020-06-24 16:06:40 +06:30
Widget getShippingAddressList(BuildContext context) {
var shipmentModel = Provider.of<ShipmentModel>(context);
return Container(
padding: EdgeInsets.only(top: 5, left: 10),
child: ExpansionTile(
title: Text(
"Shipping Addresses",
style: TextStyle(
fontWeight: FontWeight.bold, fontStyle: FontStyle.normal),
),
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: MyDataTable(
headingRowHeight: 40,
columnSpacing: 50,
columns: [
MyDataColumn(
label: Text(
"Full Name",
style: TextStyle(
fontSize: 15,
color: Colors.grey[600],
),
)),
MyDataColumn(
label: Text(
"Phone Number",
style: TextStyle(
fontSize: 15,
color: Colors.grey[600],
),
)),
MyDataColumn(
label: Text(
"Delete",
style: TextStyle(
fontSize: 15,
color: Colors.grey[600],
),
)),
],
rows: getAddressRows(shipmentModel.shippingAddresses),
),
),
),
Container(
padding: EdgeInsets.only(top: 20, bottom: 15, right: 15),
child: Align(
alignment: Alignment.bottomRight,
child: Container(
width: 120,
height: 40,
child: FloatingActionButton.extended(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
Navigator.push(
context,
BottomUpPageRoute(ShippingAddressEditor()),
);
},
label: Text(
'Add Shipping\nAddress',
style: TextStyle(fontSize: 12),
),
backgroundColor: primaryColor,
),
),
),
)
],
),
);
}
List<MyDataRow> getAddressRows(List<ShippingAddress> addresses) {
return addresses.map((s) {
return MyDataRow(
onSelectChanged: (selected) {
Navigator.push(
context,
BottomUpPageRoute(ShippingAddressEditor(shippingAddress: s)),
);
},
cells: [
MyDataCell(
new Text(
s.fullName,
style: textStyle,
),
),
MyDataCell(
new Text(
s.phoneNumber,
style: textStyle,
),
),
MyDataCell(IconButton(icon: Icon(Icons.delete), onPressed: null)),
],
);
}).toList();
}
2020-05-29 07:45:27 +06:30
Widget getPrivilegeBox(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
var userModel = Provider.of<UserModel>(context);
2020-05-29 15:53:37 +06:30
2020-05-29 07:45:27 +06:30
return ListTileTheme(
contentPadding: EdgeInsets.all(0),
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: "MyanmarUnicode"),
),
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children:
getRowPrivilegeWidget(userModel.getUserPrivileges())),
),
)
],
),
);
}
List<Widget> getRowPrivilegeWidget(List<Privilege> privileges) {
return privileges.map((p) {
return Container(
padding: EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(p.name,
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal)),
SizedBox(
width: 30,
),
Container(
child: Text(
"- ${p.desc}",
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
),
)
],
),
);
}).toList();
}
}