160 lines
5.4 KiB
Dart
160 lines
5.4 KiB
Dart
import 'package:country_code_picker/country_code_picker.dart';
|
|
import 'package:fcs/fcs/common/helpers/theme.dart';
|
|
import 'package:fcs/fcs/common/localization/app_translations.dart';
|
|
import 'package:fcs/fcs/common/pages/customers/model/customer_model.dart';
|
|
import 'package:fcs/fcs/common/pages/util.dart';
|
|
import 'package:fcs/widget/progress.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class InvitationDetail extends StatefulWidget {
|
|
@override
|
|
_InvitationDetailState createState() => _InvitationDetailState();
|
|
}
|
|
|
|
class _InvitationDetailState extends State<InvitationDetail> {
|
|
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) {
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
leading: new IconButton(
|
|
icon: new Icon(
|
|
Icons.close,
|
|
),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
backgroundColor: primaryColor,
|
|
title: Text(AppTranslations.of(context).text("invitation.new")),
|
|
),
|
|
body: Container(
|
|
padding: EdgeInsets.all(18),
|
|
child: Column(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: ListView(
|
|
children: <Widget>[
|
|
fcsInput("Name", Icons.person,
|
|
controller: _nameController, autoFocus: true),
|
|
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,
|
|
countryFilter: ['+95', '+1'],
|
|
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: "Phone number",
|
|
labelStyle:
|
|
TextStyle(fontSize: 16, color: Colors.grey),
|
|
filled: true,
|
|
focusedBorder: UnderlineInputBorder(
|
|
borderSide: BorderSide(
|
|
color: Colors.grey, width: 1.0)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
fcsButton(context, "Invite", callack: _invite),
|
|
SizedBox(height: 10)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_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;
|
|
});
|
|
}
|
|
}
|
|
}
|