Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

285 wiersze
8.5 KiB

  1. import 'package:chat/data/WebData.dart';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/home/Registerpage.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:chat/utils/screen.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:oktoast/oktoast.dart';
  10. import '../utils/OtherLogin.dart';
  11. import '../utils/HttpUtil.dart';
  12. import "../data/UserData.dart";
  13. const RATE_NUM = 0.82;
  14. //const BlueColor = const Color(0xFF93C3FF);
  15. const BlueColor = Constants.BlueTextColor;
  16. class LoginPage extends StatefulWidget {
  17. LoginPage({Key key, bool flag}) : super(key: key);
  18. _LoginPageState createState() => _LoginPageState();
  19. }
  20. class _LoginPageState extends State<LoginPage> {
  21. String _phoneNumber = '';
  22. String _passWorld = '';
  23. String _selectType = UserData().language == LanguageType.Vietnamese
  24. ? phone.keys.toList()[1]
  25. : phone.keys.toList()[0];
  26. @override
  27. Widget build(BuildContext context) {
  28. var keyHeight = MediaQuery.of(context).viewInsets.bottom;
  29. if (keyHeight > 0) {
  30. UserData().setKeyboardHeight(keyHeight);
  31. }
  32. Widget appBar = AppBar(
  33. backgroundColor: AppColors.NewAppbarBgColor,
  34. title: Text(
  35. I18n.of(context).login,
  36. textScaleFactor: 1.0,
  37. style: TextStyle(color: AppColors.NewAppbarTextColor),
  38. ),
  39. leading: CustomUI.buildCustomLeading(context),
  40. centerTitle: true,
  41. );
  42. return Scaffold(
  43. body: SafeArea(
  44. child: Center(
  45. child: Container(
  46. height: MediaQuery.of(context).size.height,
  47. width: MediaQuery.of(context).size.width,
  48. child: _buildBody(),
  49. ),
  50. )),
  51. appBar: appBar,
  52. resizeToAvoidBottomPadding: false,
  53. );
  54. }
  55. @override
  56. void initState() {
  57. super.initState();
  58. print('LoginPage initState');
  59. }
  60. @override
  61. void dispose() {
  62. super.dispose();
  63. }
  64. Widget _buildBody() {
  65. return new Column(
  66. children: <Widget>[
  67. _buildAcountInput(),
  68. _buildPasswordInput(),
  69. _buildForgetPassWord(),
  70. SizedBox(
  71. height: 40,
  72. ),
  73. _buildLoginButton(),
  74. _buildOtherLogin(),
  75. ],
  76. );
  77. }
  78. //构建底部第三方登陆
  79. Widget _buildOtherLogin() {
  80. return new Expanded(
  81. child: Column(
  82. mainAxisAlignment: MainAxisAlignment.end,
  83. children: <Widget>[
  84. new Container(
  85. alignment: Alignment.bottomCenter,
  86. child: OtherLogin().builder(context),
  87. )
  88. ],
  89. ),
  90. );
  91. }
  92. //账号输入框
  93. Widget _buildAcountInput() {
  94. double height = 54.5;
  95. return new Container(
  96. alignment: Alignment.center,
  97. margin: EdgeInsets.only(top: 8.5),
  98. height: height,
  99. padding: EdgeInsets.only(left: 17),
  100. decoration: BoxDecoration(
  101. color: Colors.white,
  102. border: Border(
  103. top: Constants.GreyBorderSide,
  104. bottom: Constants.GreyBorderSide)),
  105. child: Stack(
  106. children: <Widget>[
  107. Container(
  108. width: Screen.width,
  109. height: height,
  110. alignment: Alignment.centerLeft,
  111. child: Icon(
  112. Icons.phone_android,
  113. color: BlueColor,
  114. size: Constants.TextFieldIconSize,
  115. ),
  116. ),
  117. Positioned(
  118. left: 46,
  119. child: Container(
  120. padding: EdgeInsets.only(top: 5),
  121. margin: EdgeInsets.all(0),
  122. alignment: Alignment.centerLeft,
  123. child: new DropdownButtonHideUnderline(
  124. child: new DropdownButton(
  125. items: phone.keys.map((key) {
  126. return DropdownMenuItem(
  127. child: new Text(key, textScaleFactor: 1.0),
  128. value: key,
  129. );
  130. }).toList(),
  131. onChanged: (value) {
  132. setState(() {
  133. _selectType = value;
  134. });
  135. },
  136. value: _selectType,
  137. elevation: 24, //设置阴影的高度
  138. style: new TextStyle(
  139. //设置文本框里面文字的样式
  140. color: Constants.BlackTextColor,
  141. fontSize: 12,
  142. ),
  143. iconSize: 25.0,
  144. )),
  145. ),
  146. ),
  147. Positioned(
  148. left: 90,
  149. child: Container(
  150. alignment: Alignment.center,
  151. width: Screen.width - 90,
  152. height: height,
  153. child: TextField(
  154. keyboardAppearance: Brightness.light,
  155. decoration: new InputDecoration(
  156. hintText: I18n.of(context).enter_number,
  157. hintStyle: TextStyle(fontSize: 14),
  158. border: InputBorder.none,
  159. ),
  160. maxLines: 1,
  161. style: TextStyle(textBaseline: TextBaseline.alphabetic),
  162. inputFormatters: [
  163. WhitelistingTextInputFormatter.digitsOnly,
  164. ],
  165. onChanged: (str) {
  166. _phoneNumber = str;
  167. //_phoneNumber = str;
  168. setState(() {});
  169. },
  170. keyboardType: TextInputType.phone,
  171. ),
  172. ),
  173. )
  174. ],
  175. ));
  176. }
  177. //构建密码按钮
  178. Widget _buildPasswordInput() {
  179. return new Container(
  180. alignment: Alignment.center,
  181. child: new TextField(
  182. keyboardAppearance: Brightness.light,
  183. decoration: new InputDecoration(
  184. hintText: I18n.of(context).enter_password,
  185. hintStyle: TextStyle(fontSize: 14),
  186. icon: new Icon(
  187. Icons.lock,
  188. color: BlueColor,
  189. size: Constants.TextFieldIconSize,
  190. ),
  191. border: InputBorder.none,
  192. ),
  193. style: TextStyle(textBaseline: TextBaseline.alphabetic),
  194. maxLines: 1,
  195. obscureText: true,
  196. onChanged: (str) {
  197. _passWorld = str;
  198. setState(() {});
  199. },
  200. ),
  201. height: 54.5,
  202. padding: EdgeInsets.only(left: 17),
  203. decoration: BoxDecoration(
  204. color: Colors.white,
  205. border: Border(bottom: Constants.GreyBorderSide)),
  206. );
  207. }
  208. //构建忘记密码
  209. Widget _buildForgetPassWord() {
  210. return new Container(
  211. child: new Align(
  212. alignment: FractionalOffset.centerRight,
  213. child: new FlatButton(
  214. child: new Text(
  215. I18n.of(context).forget_password,
  216. textScaleFactor: 1.0,
  217. style: TextStyle(color: BlueColor),
  218. ),
  219. onPressed: () {
  220. Navigator.of(context).push(
  221. new MaterialPageRoute(
  222. builder: (context) {
  223. return RegisterPage(
  224. type: PageType.changePWD.index,
  225. );
  226. },
  227. ),
  228. );
  229. },
  230. ),
  231. ),
  232. );
  233. }
  234. //构建登陆按钮
  235. Widget _buildLoginButton() {
  236. Text text = new Text(I18n.of(context).login,
  237. textScaleFactor: 1.0,
  238. style: TextStyle(
  239. fontSize: Constants.ShaderButtonFontSize, color: Colors.white));
  240. callback() async {
  241. if (_phoneNumber == null || _phoneNumber == "") {
  242. showToast(I18n.of(context).enter_number);
  243. return;
  244. }
  245. if (_passWorld == null || _passWorld == "") {
  246. showToast(I18n.of(context).enter_password);
  247. return;
  248. }
  249. HttpUtil().login(phone[_selectType] + _phoneNumber, _passWorld, context);
  250. }
  251. return InkWell(
  252. onTap: callback,
  253. child: Container(
  254. // margin: EdgeInsets.only(top: 40),
  255. alignment: Alignment.center,
  256. height: Constants.ShaderButtonHeight,
  257. width: Screen.width * RATE_NUM,
  258. decoration: BoxDecoration(
  259. color: Constants.ConfrimButtonColor,
  260. border: Border.all(color: const Color(0x803875E9)),
  261. borderRadius:
  262. BorderRadius.all(Radius.circular(Constants.BigButtonRadius))),
  263. child: text,
  264. ),
  265. );
  266. }
  267. }