insert pages
This commit is contained in:
175
lib/pages/signin_page.dart
Normal file
175
lib/pages/signin_page.dart
Normal file
@@ -0,0 +1,175 @@
|
||||
import 'package:country_code_picker/country_code_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
import '../widget/local_text.dart';
|
||||
import '../widget/progress.dart';
|
||||
import 'code_page.dart';
|
||||
import 'util.dart';
|
||||
|
||||
class SigninPage extends StatefulWidget {
|
||||
@override
|
||||
_SigninPageState createState() => _SigninPageState();
|
||||
}
|
||||
|
||||
class _SigninPageState extends State<SigninPage> {
|
||||
bool _isLoading = false;
|
||||
String dialCode;
|
||||
|
||||
TextEditingController phonenumberCtl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
phonenumberCtl = new TextEditingController(text: "09");
|
||||
phonenumberCtl.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: phonenumberCtl.text.length));
|
||||
|
||||
dialCode = "+95";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: new Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: _buildLogin(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogin(BuildContext context) {
|
||||
return ListView(
|
||||
padding: EdgeInsets.only(top: 5, left: 15, right: 15),
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 40),
|
||||
child: LocalText(
|
||||
context,
|
||||
'login.title',
|
||||
fontSize: 21,
|
||||
color: secondaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 25),
|
||||
child: LocalText(
|
||||
context,
|
||||
'login.phone',
|
||||
color: labelColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
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', '+65', '+66'],
|
||||
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(
|
||||
autofocus: true,
|
||||
controller: phonenumberCtl,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.phone,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
contentPadding: EdgeInsets.all(8.0),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12.0)),
|
||||
borderSide:
|
||||
BorderSide(color: Colors.grey[400], width: 1),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
borderSide: BorderSide(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () => _next(),
|
||||
child: CircleAvatar(
|
||||
minRadius: 25,
|
||||
backgroundColor: primaryColor,
|
||||
child: Icon(
|
||||
FontAwesomeIcons.arrowRight,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_countryChange(CountryCode countryCode) {
|
||||
setState(() {
|
||||
dialCode = countryCode.dialCode;
|
||||
});
|
||||
}
|
||||
|
||||
_next() async {
|
||||
String phoneNumber = phonenumberCtl.text;
|
||||
if (phoneNumber.length < 5) {
|
||||
showMsgDialog(context, "Error", "Invalid phone number");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Exception exp;
|
||||
phoneNumber = phoneNumber[0] == "0"
|
||||
? phoneNumber.replaceFirst("0", "")
|
||||
: phoneNumber;
|
||||
phoneNumber = dialCode + phoneNumber;
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CodePage(phoneNumber: phoneNumber)));
|
||||
|
||||
if (exp != null) throw exp;
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user