Files
fcs/lib/pages/customer/invitation_create.dart

165 lines
5.1 KiB
Dart
Raw Normal View History

2020-09-15 07:13:41 +06:30
import 'package:country_code_picker/country_code_picker.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/customer/model/customer_model.dart';
import 'package:fcs/pages/main/util.dart';
2020-10-07 14:42:07 +06:30
import 'package:fcs/pages/widgets/input_text.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
2020-09-15 07:13:41 +06:30
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class InvitationCreate extends StatefulWidget {
@override
_InvitationCreateState createState() => _InvitationCreateState();
}
class _InvitationCreateState extends State<InvitationCreate> {
TextEditingController _nameController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
bool _isLoading = false;
String dialCode;
@override
void initState() {
super.initState();
dialCode = "+95";
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
2020-10-07 14:42:07 +06:30
final nameBox = InputText(
labelTextKey: 'customer.name',
iconData: Icons.person,
controller: _nameController);
2020-09-15 07:13:41 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
2020-09-18 04:04:21 +06:30
backgroundColor: Colors.white,
shadowColor: Colors.transparent,
2020-09-15 07:13:41 +06:30
centerTitle: true,
leading: new IconButton(
icon: new Icon(
Icons.close,
2020-09-18 04:04:21 +06:30
color: primaryColor,
2020-09-15 07:13:41 +06:30
),
onPressed: () => Navigator.of(context).pop(),
),
2020-09-18 04:04:21 +06:30
title: LocalText(
context,
"invitation.new",
fontSize: 20,
color: primaryColor,
),
2020-09-15 07:13:41 +06:30
),
body: Container(
padding: EdgeInsets.all(18),
child: ListView(
children: <Widget>[
2020-10-07 14:42:07 +06:30
nameBox,
2020-09-15 07:13:41 +06:30
SizedBox(height: 10),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.phone,
color: primaryColor,
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[400], width: 1),
borderRadius: BorderRadius.all(Radius.circular(12.0))),
child: CountryCodePicker(
onChanged: _countryChange,
initialSelection: dialCode,
2020-10-08 11:38:05 +06:30
countryFilter: ['mm', 'us'],
2020-09-15 07:13:41 +06:30
showCountryOnly: false,
showOnlyCountryWhenClosed: false,
alignLeft: false,
textStyle: TextStyle(
fontSize: 16,
),
),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: TextFormField(
controller: _phoneController,
cursorColor: primaryColor,
textAlign: TextAlign.left,
keyboardType: TextInputType.phone,
style: TextStyle(
fontSize: 18,
),
decoration: InputDecoration(
fillColor: Colors.white,
labelText: getLocalString(context, "customer.phone"),
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.grey, width: 1.0)),
),
),
),
),
],
),
SizedBox(height: 20),
fcsButton(context, getLocalString(context, "invite.btn"),
callack: _invite),
],
),
),
),
);
}
_countryChange(CountryCode countryCode) {
setState(() {
dialCode = countryCode.dialCode;
});
}
_invite() async {
String userName = _nameController.text;
String phoneNumber = dialCode + _phoneController.text;
if (userName == null ||
userName == "" ||
phoneNumber == null ||
phoneNumber == "") {
showMsgDialog(context, "Error", "Invalid name or phone number");
return;
}
setState(() {
_isLoading = true;
});
try {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
await customerModel.inviteUser(userName, phoneNumber);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}