Files
fcs/lib/pages/profile/profile_page.dart

346 lines
10 KiB
Dart
Raw Normal View History

2020-10-07 02:33:06 +06:30
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';
2020-09-12 03:34:52 +06:30
import 'package:flutter/cupertino.dart';
2020-08-30 21:26:37 +06:30
import 'package:flutter/material.dart';
2020-09-13 21:49:39 +06:30
import 'package:flutter/services.dart';
2020-08-30 21:26:37 +06:30
import 'package:provider/provider.dart';
2020-05-29 07:45:27 +06:30
2020-09-13 21:49:39 +06:30
import '../../helpers/theme.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> {
2020-09-13 21:49:39 +06:30
GlobalKey key = GlobalKey();
2020-05-29 07:45:27 +06:30
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);
2020-09-16 02:29:50 +06:30
if (mainModel.user == null) {
return Container();
}
2020-09-13 21:49:39 +06:30
final namebox = DisplayText(
text: mainModel.user.name,
2020-10-08 03:32:52 +06:30
labelTextKey: getLocalString(context, "profile.name"),
2020-09-13 21:49:39 +06:30
iconData: Icons.person,
);
2020-06-24 16:06:40 +06:30
2020-09-13 21:49:39 +06:30
final phonenumberbox = DisplayText(
text: mainModel.user.phone,
2020-10-08 03:32:52 +06:30
labelTextKey: getLocalString(context, "profile.phone"),
2020-09-13 21:49:39 +06:30
iconData: Icons.phone,
);
final fcsIDBox = Row(
children: [
Expanded(
child: DisplayText(
text: mainModel.user.fcsID,
2020-10-08 03:32:52 +06:30
labelTextKey: getLocalString(context, "customer.fcs.id"),
2020-09-18 04:04:21 +06:30
icon: FcsIDIcon(),
2020-05-29 07:45:27 +06:30
),
2020-09-13 21:49:39 +06:30
),
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,
2020-10-08 03:32:52 +06:30
labelTextKey:
getLocalString(context, "profile.usa.shipping.address"),
2020-09-13 21:49:39 +06:30
iconData: Icons.location_on,
2020-05-29 07:45:27 +06:30
),
2020-09-13 21:49:39 +06:30
),
IconButton(
icon: Icon(Icons.content_copy, color: Colors.grey),
onPressed: () => _copy(
getLocalString(context, "profile.usa.shipping.address"),
mainModel.setting.usaAddress),
)
],
2020-05-29 07:45:27 +06:30
);
2020-09-13 21:49:39 +06:30
final logoutbutton = fcsButton(
context, getLocalString(context, "profile.logout"),
callack: _logout, iconData: Icons.exit_to_app);
2020-05-29 07:45:27 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
2020-09-13 21:49:39 +06:30
key: key,
2020-05-29 07:45:27 +06:30
appBar: AppBar(
2020-09-13 21:49:39 +06:30
centerTitle: true,
2020-09-12 03:34:52 +06:30
leading: IconButton(
icon: Icon(
CupertinoIcons.back,
2020-09-13 21:49:39 +06:30
size: 35,
color: primaryColor,
2020-09-12 03:34:52 +06:30
),
onPressed: () => Navigator.of(context).pop(),
),
2020-09-18 04:04:21 +06:30
title: LocalText(
context,
"profile.title",
fontSize: 20,
color: primaryColor,
2020-05-29 07:45:27 +06:30
),
2020-09-13 21:49:39 +06:30
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
2020-06-24 16:06:40 +06:30
actions: <Widget>[],
2020-05-29 07:45:27 +06:30
),
2020-09-13 21:49:39 +06:30
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,
2020-09-20 08:06:14 +06:30
DisplayText(
text: mainModel.user.status,
2020-10-08 03:32:52 +06:30
labelTextKey: getLocalString(context, "customer.status"),
2020-09-20 08:06:14 +06:30
iconData: Icons.add_alarm,
),
2020-09-13 21:49:39 +06:30
// getShippingAddressList(context),
],
),
2020-06-25 16:19:23 +06:30
),
2020-09-13 21:49:39 +06:30
logoutbutton,
SizedBox(height: 25)
],
),
2020-05-29 07:45:27 +06:30
),
),
);
}
2020-06-24 16:06:40 +06:30
Widget getShippingAddressList(BuildContext context) {
2020-10-07 02:33:06 +06:30
var shipmentModel = Provider.of<ShipmentAddressModel>(context);
2020-06-24 16:06:40 +06:30
return Container(
padding: EdgeInsets.only(top: 5, left: 10),
child: ExpansionTile(
title: Text(
2020-06-30 16:11:58 +06:30
"My Addresses",
2020-06-24 16:06:40 +06:30
style: TextStyle(
fontWeight: FontWeight.bold, fontStyle: FontStyle.normal),
),
children: <Widget>[
2020-06-25 16:19:23 +06:30
Column(
children: getAddressList(context, shipmentModel.shippingAddresses),
2020-06-24 16:06:40 +06:30
),
Container(
padding: EdgeInsets.only(top: 20, bottom: 15, right: 15),
child: Align(
alignment: Alignment.bottomRight,
child: Container(
2020-06-26 16:17:40 +06:30
width: 130,
2020-06-24 16:06:40 +06:30
height: 40,
child: FloatingActionButton.extended(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
Navigator.push(
context,
BottomUpPageRoute(ShippingAddressEditor()),
);
},
2020-06-26 16:17:40 +06:30
icon: Icon(Icons.add),
2020-06-24 16:06:40 +06:30
label: Text(
2020-06-30 16:11:58 +06:30
'Add New\nAddress',
2020-06-24 16:06:40 +06:30
style: TextStyle(fontSize: 12),
),
backgroundColor: primaryColor,
),
),
),
)
],
),
);
}
2020-06-25 16:19:23 +06:30
List<Widget> getAddressList(
BuildContext context, List<ShippingAddress> addresses) {
return addresses.asMap().entries.map((s) {
2020-06-26 16:17:40 +06:30
return InkWell(
onTap: () {
Navigator.push(
context,
BottomUpPageRoute(ShippingAddressEditor(shippingAddress: s.value)),
);
},
child: ShippingAddressRow(shippingAddress: s.value, index: s.key),
2020-06-24 16:06:40 +06:30
);
}).toList();
}
2020-10-07 02:33:06 +06:30
List<Privilege> privileges = [
Privilege(name: 'Manage shipment'),
Privilege(name: 'Manage pickups'),
Privilege(name: 'Manage packages'),
Privilege(name: 'Manage deliveries'),
Privilege(name: 'Admin')
];
2020-05-29 07:45:27 +06:30
Widget getPrivilegeBox(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(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,
2020-10-07 02:33:06 +06:30
fontFamily: "Myanmar3"),
2020-05-29 07:45:27 +06:30
),
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2020-10-07 02:33:06 +06:30
children: getRowPrivilegeWidget(privileges)),
2020-05-29 07:45:27 +06:30
),
)
],
),
);
}
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();
}
2020-09-13 21:49:39 +06:30
_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;
});
2020-09-22 03:52:48 +06:30
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;
});
}
});
}
2020-09-13 21:49:39 +06:30
});
}
2020-05-29 07:45:27 +06:30
}