import 'package:fcs/domain/entities/user.dart'; import 'package:fcs/domain/vo/privilege.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/staff/model/staff_model.dart'; import 'package:fcs/pages/widgets/display_text.dart'; import 'package:fcs/pages/widgets/fcs_id_icon.dart'; import 'package:fcs/pages/widgets/local_app_bar.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:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; import 'staff_pin_editor.dart'; import 'staff_privilege_editor.dart'; class StaffInfo extends StatefulWidget { final User staff; const StaffInfo({required this.staff}); @override _StaffInfoState createState() => _StaffInfoState(); } class _StaffInfoState extends State { bool _isLoading = false; late User _staff; List _privileges = []; @override void initState() { _staff = widget.staff; _init(); super.initState(); } _init() { List list = Provider.of(context, listen: false).privileges; list.forEach((p) => _staff.privileges.contains(p.id) ? p.isChecked = true : p.isChecked = false); _privileges = list.where((e) => e.isChecked ?? false).toList(); if (mounted) { setState(() {}); } } List showprivilegeList(BuildContext context) { return _privileges.map((p) { return new ListTile( title: new Row( children: [ Padding( padding: const EdgeInsets.only(right: 8.0), child: Icon(p.iconData, size: 30, color: Colors.black38), ), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( p.name ?? "", style: TextStyle(fontSize: 15.0, color: Colors.black), ), Text(p.desc ?? "", style: TextStyle(fontSize: 13, color: labelColor)) ], ), ), ], )); }).toList(); } @override Widget build(BuildContext context) { final fcsIdBox = DisplayText( text: _staff.fcsID, labelTextKey: "customer.fcs.id", icon: FcsIDIcon(), ); final namebox = DisplayText( text: _staff.name, labelTextKey: "customer.name", iconData: Icons.person, ); final phoneNumberBox = Row( children: [ Expanded( child: DisplayText( text: _staff.phoneNumber, labelTextKey: "customer.phone", iconData: Icons.phone, )), IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), onPressed: () => call(context, _staff.phoneNumber!)), ], ); final pinBox = Row( children: [ Expanded( child: DisplayText( text: _staff.enablePinLogin ? "Enabled" : "Disabled", labelTextKey: "staff.pin_login", iconData: MaterialCommunityIcons.lock)), SizedBox( width: 65, height: 35, child: OutlinedButton( style: OutlinedButton.styleFrom( padding: EdgeInsets.all(5), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5.0)), side: BorderSide(color: primaryColor), ), onPressed: () async { bool? updated = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => StaffPinEditor(staff: _staff))); if (updated ?? false) { User? _u = await context.read().getUser(widget.staff.id!); if (_u == null) return; _staff = _u; _init(); } }, child: LocalText(context, 'staff.edit_pin', color: primaryColor, fontSize: 13), ), ) ], ); final privilegeTitleBox = Row( children: [ Expanded( child: LocalText(context, 'staff.privilege.title', color: Colors.black54, fontSize: 15)), SizedBox( width: 100, height: 35, child: OutlinedButton( style: OutlinedButton.styleFrom( padding: EdgeInsets.all(5), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5.0)), side: BorderSide(color: primaryColor), ), onPressed: () async { bool? updated = await Navigator.of(context).push( CupertinoPageRoute( builder: (context) => StaffPrivilegeEditor(staff: _staff))); if (updated ?? false) { User? _u = await context.read().getUser(widget.staff.id!); if (_u == null) return; _staff = _u; _init(); } }, child: LocalText(context, 'staff.edit_privileges', color: primaryColor, fontSize: 13), ), ) ], ); return LocalProgress( inAsyncCall: _isLoading, child: Scaffold( appBar: LocalAppBar( labelKey: "staff.form.title", backgroundColor: Colors.white, labelColor: primaryColor, arrowColor: primaryColor), body: Padding( padding: const EdgeInsets.only(left: 12.0, right: 12), child: ListView( children: [ fcsIdBox, phoneNumberBox, namebox, pinBox, const SizedBox(height: 10), privilegeTitleBox, Column(children: showprivilegeList(context)), SizedBox(height: 30) ], ), ), )); } }