完成登陆功能

hmxc
小赖 4 years ago
parent bb1ba14b5d
commit 66c81579b3

@ -2,13 +2,16 @@ import 'dart:ui';
import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/style/app_style.dart';
import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart';
import 'package:aku_community_manager/ui/login/login_sms_page.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart';
import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart';
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:extended_text/extended_text.dart'; import 'package:extended_text/extended_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/screen_tool.dart';
import 'package:get/route_manager.dart';
class LoginPage extends StatefulWidget { class LoginPage extends StatefulWidget {
LoginPage({Key key}) : super(key: key); LoginPage({Key key}) : super(key: key);
@ -24,6 +27,10 @@ class _LoginPageState extends State<LoginPage> {
return RegexUtil.isMobileSimple(_textController.text); return RegexUtil.isMobileSimple(_textController.text);
} }
bool get emptyText {
return TextUtil.isEmpty(_textController.text);
}
@override @override
void dispose() { void dispose() {
_textController?.dispose(); _textController?.dispose();
@ -36,34 +43,28 @@ class _LoginPageState extends State<LoginPage> {
backgroundColor: Colors.white, backgroundColor: Colors.white,
leading: AkuBackButton.close(), leading: AkuBackButton.close(),
body: ListView( body: ListView(
padding: EdgeInsets.symmetric(
vertical: 40.w,
horizontal: 32.w,
),
children: [ children: [
Padding( Text(
padding: EdgeInsets.only( '欢迎登录小蜜蜂',
top: 40.w, style: TextStyle(
bottom: 184.w, color: AppStyle.primaryTextColor,
left: 32.w, fontWeight: FontWeight.bold,
), fontSize: 48.sp,
child: Text(
'欢迎登录小蜜蜂',
style: TextStyle(
color: AppStyle.primaryTextColor,
fontWeight: FontWeight.bold,
fontSize: 48.sp,
),
), ),
), ),
Padding( AkuBox.h(184),
padding: EdgeInsets.symmetric(horizontal: 32.w), Text(
child: Text( '手机号码',
'手机号码', style: TextStyle(
style: TextStyle( color: AppStyle.primaryTextColor,
color: AppStyle.primaryTextColor, fontSize: 24.sp,
fontSize: 24.sp,
),
), ),
), ),
Container( Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
width: double.infinity, width: double.infinity,
child: TextField( child: TextField(
autofocus: true, autofocus: true,
@ -73,6 +74,23 @@ class _LoginPageState extends State<LoginPage> {
}, },
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
decoration: InputDecoration( decoration: InputDecoration(
suffixIconConstraints: BoxConstraints(
minHeight: 0,
minWidth: 0,
),
suffixIcon: emptyText
? SizedBox()
: GestureDetector(
onTap: () {
_textController.clear();
setState(() {});
},
child: Icon(
CupertinoIcons.clear_circled_solid,
size: 30.w,
color: Color(0xFF999999),
),
),
border: UnderlineInputBorder( border: UnderlineInputBorder(
borderSide: BorderSide( borderSide: BorderSide(
color: Color(0xFFE8E8E8), color: Color(0xFFE8E8E8),
@ -93,7 +111,9 @@ class _LoginPageState extends State<LoginPage> {
padding: EdgeInsets.symmetric(horizontal: 32.w), padding: EdgeInsets.symmetric(horizontal: 32.w),
child: AkuMaterialButton( child: AkuMaterialButton(
color: AppStyle.primaryColor, color: AppStyle.primaryColor,
onPressed: phoneValid ? () {} : null, onPressed: phoneValid
? () => Get.off(LoginSMSPage(phone: _textController.text))
: null,
nullColor: Color(0xFFFFE67D), nullColor: Color(0xFFFFE67D),
radius: 8.w, radius: 8.w,
child: Text( child: Text(

@ -0,0 +1,126 @@
import 'dart:async';
import 'package:aku_community_manager/provider/user_provider.dart';
import 'package:aku_community_manager/style/app_style.dart';
import 'package:aku_community_manager/tools/widget_tool.dart';
import 'package:aku_community_manager/ui/home/home_page.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart';
import 'package:aku_ui/common_widgets/aku_material_button.dart';
import 'package:flutter/material.dart';
import 'package:aku_community_manager/tools/screen_tool.dart';
import 'package:get/get.dart';
import 'package:pin_input_text_field/pin_input_text_field.dart';
import 'package:provider/provider.dart';
class LoginSMSPage extends StatefulWidget {
final String phone;
LoginSMSPage({Key key, this.phone}) : super(key: key);
@override
_LoginSMSPageState createState() => _LoginSMSPageState();
}
class _LoginSMSPageState extends State<LoginSMSPage> {
TextEditingController _textEditingController = TextEditingController();
int _count = 60;
Timer _countTimer;
bool get canResend => _count <= 0;
String get countString {
if (_count <= 0)
return '';
else
return '$_count\s';
}
startTick() {
_count = 60;
_countTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (_count >= 0)
_count--;
else {
_countTimer?.cancel();
}
setState(() {});
});
}
@override
void initState() {
super.initState();
startTick();
}
@override
void dispose() {
_textEditingController?.dispose();
_countTimer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AkuScaffold(
backgroundColor: Colors.white,
leading: AkuBackButton(),
body: ListView(
padding: EdgeInsets.symmetric(
horizontal: 32.w,
vertical: 40.w,
),
children: [
Text(
'请输入短信验证码',
style: TextStyle(
color: AppStyle.primaryTextColor,
fontWeight: FontWeight.bold,
fontSize: 48.sp,
),
),
AkuBox.h(16),
Text(
'已向${widget.phone}发送了一个验证码',
style: TextStyle(
color: AppStyle.primaryTextColor,
fontSize: 24.sp,
),
),
AkuBox.h(160),
PinInputTextField(
controller: _textEditingController,
autoFocus: true,
decoration: UnderlineDecoration(
lineHeight: 1.w,
colorBuilder: FixedColorBuilder(Color(0xFFE8E8E8)),
),
onChanged: (text) {
final userProvider =
Provider.of<UserProvider>(context, listen: false);
if (text == '000000') {
userProvider.setisSigned(true);
Get.offAll(HomePage());
}
},
),
AkuBox.h(40),
Row(
children: [
AkuMaterialButton(
onPressed: canResend ? () => startTick() : null,
child: Text(
'重新发送 $countString',
style: TextStyle(
color: canResend
? AppStyle.secondaryColor
: AppStyle.minorTextColor,
fontSize: 28.sp,
),
),
),
],
),
],
),
);
}
}

@ -181,6 +181,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.8.0-nullsafety.1" version: "1.8.0-nullsafety.1"
pin_input_text_field:
dependency: "direct main"
description:
name: pin_input_text_field
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.1"
provider: provider:
dependency: "direct main" dependency: "direct main"
description: description:

@ -45,6 +45,8 @@ dependencies:
extended_text: ^4.0.0 extended_text: ^4.0.0
common_utils: ^1.2.1 common_utils: ^1.2.1
#验证码
pin_input_text_field: ^3.1.1
aku_ui: aku_ui:
git: git:

Loading…
Cancel
Save