clean up
This commit is contained in:
109
lib/pages/profile/profile_edit.dart
Normal file
109
lib/pages/profile/profile_edit.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
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();
|
||||
|
||||
class ProfileEdit extends StatefulWidget {
|
||||
@override
|
||||
_ProfileEditState createState() => _ProfileEditState();
|
||||
}
|
||||
|
||||
class _ProfileEditState extends State<ProfileEdit> {
|
||||
final TextEditingController nameController = new TextEditingController();
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
nameController.text = mainModel.user.name;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
|
||||
final name = Container(
|
||||
padding: EdgeInsets.only(top: 0, left: 20, right: 15, bottom: 30),
|
||||
child: TextFormField(
|
||||
controller: nameController,
|
||||
autofocus: true,
|
||||
cursorColor: primaryColor,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: AppTranslations.of(context).text("profile.name"),
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
Icons.person,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
));
|
||||
|
||||
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_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>[
|
||||
Expanded(child: name),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: saveBtn,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
try {
|
||||
await Provider.of<MainModel>(context, listen: false)
|
||||
.updateProfile(nameController.text);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
344
lib/pages/profile/profile_page.dart
Normal file
344
lib/pages/profile/profile_page.dart
Normal file
@@ -0,0 +1,344 @@
|
||||
import 'package:fcs/domain/entities/role.dart';
|
||||
import 'package:fcs/domain/vo/shipping_address.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/localization/transalation.dart';
|
||||
import 'package:fcs/pages/main/model/language_model.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/profile/profile_edit.dart';
|
||||
import 'package:fcs/pages/shipment_address/model/shipment_address_model.dart';
|
||||
import 'package:fcs/pages/shipment_address/shipping_address_editor.dart';
|
||||
import 'package:fcs/pages/shipment_address/shipping_address_row.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:provider/provider.dart';
|
||||
|
||||
import '../../helpers/theme.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class Profile extends StatefulWidget {
|
||||
@override
|
||||
_ProfileState createState() => _ProfileState();
|
||||
}
|
||||
|
||||
class _ProfileState extends State<Profile> {
|
||||
GlobalKey key = GlobalKey();
|
||||
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) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
if (mainModel.user == null) {
|
||||
return Container();
|
||||
}
|
||||
final namebox = DisplayText(
|
||||
text: mainModel.user.name,
|
||||
labelText: getLocalString(context, "profile.name"),
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final phonenumberbox = DisplayText(
|
||||
text: mainModel.user.phone,
|
||||
labelText: getLocalString(context, "profile.phone"),
|
||||
iconData: Icons.phone,
|
||||
);
|
||||
final fcsIDBox = Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.user.fcsID,
|
||||
labelText: getLocalString(context, "customer.fcs.id"),
|
||||
icon: FcsIDIcon(),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.content_copy, color: Colors.grey),
|
||||
onPressed: () => _copy(
|
||||
getLocalString(context, "customer.fcs.id"), mainModel.user.fcsID),
|
||||
)
|
||||
],
|
||||
);
|
||||
final usaShippingAddressBox = Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.setting.usaAddress,
|
||||
labelText: getLocalString(context, "profile.usa.shipping.address"),
|
||||
iconData: Icons.location_on,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.content_copy, color: Colors.grey),
|
||||
onPressed: () => _copy(
|
||||
getLocalString(context, "profile.usa.shipping.address"),
|
||||
mainModel.setting.usaAddress),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
final logoutbutton = fcsButton(
|
||||
context, getLocalString(context, "profile.logout"),
|
||||
callack: _logout, iconData: Icons.exit_to_app);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
key: key,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
CupertinoIcons.back,
|
||||
size: 35,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
title: LocalText(
|
||||
context,
|
||||
"profile.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
actions: <Widget>[],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
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),
|
||||
phonenumberbox,
|
||||
fcsIDBox,
|
||||
usaShippingAddressBox,
|
||||
DisplayText(
|
||||
text: mainModel.user.status,
|
||||
labelText: getLocalString(context, "customer.status"),
|
||||
iconData: Icons.add_alarm,
|
||||
),
|
||||
// getShippingAddressList(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
logoutbutton,
|
||||
SizedBox(height: 25)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getShippingAddressList(BuildContext context) {
|
||||
var shipmentModel = Provider.of<ShipmentAddressModel>(context);
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 10),
|
||||
child: ExpansionTile(
|
||||
title: Text(
|
||||
"My Addresses",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontStyle: FontStyle.normal),
|
||||
),
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: getAddressList(context, shipmentModel.shippingAddresses),
|
||||
),
|
||||
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: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(ShippingAddressEditor()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: Text(
|
||||
'Add New\nAddress',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getAddressList(
|
||||
BuildContext context, List<ShippingAddress> addresses) {
|
||||
return addresses.asMap().entries.map((s) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
BottomUpPageRoute(ShippingAddressEditor(shippingAddress: s.value)),
|
||||
);
|
||||
},
|
||||
child: ShippingAddressRow(shippingAddress: s.value, index: s.key),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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: "Myanmar3"),
|
||||
),
|
||||
children: <Widget>[
|
||||
Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
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),
|
||||
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();
|
||||
}
|
||||
|
||||
_copy(String title, String data) {
|
||||
Clipboard.setData(ClipboardData(text: data));
|
||||
_showToast(title);
|
||||
}
|
||||
|
||||
void _showToast(String title) {
|
||||
final ScaffoldState scaffold = key.currentState;
|
||||
scaffold.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('copied "$title" data to clipboard'),
|
||||
backgroundColor: secondaryColor,
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_editName() {
|
||||
Navigator.of(context)
|
||||
.push<void>(CupertinoPageRoute(builder: (context) => ProfileEdit()));
|
||||
}
|
||||
|
||||
_logout() {
|
||||
showConfirmDialog(context, "profile.logout.confirm", () async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
await context.read<MainModel>().signout();
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
"/welcome", ModalRoute.withName('/welcome'));
|
||||
} catch (e) {} finally {
|
||||
Future.delayed(Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user