| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- import 'dart:async';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import '../styles/colors.dart';
- import 'dart:ui';
- import '../styles/totast.dart';
- import '../widget/ITextInput.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import 'HomePage.dart';
- import '../redux/AppState.dart';
- import '../redux/UserRedux.dart';
- import '../model/UserInfo.dart';
- import '../widget/LinearButton.dart';
- import '../widget/Dialog.dart';
- import '../model/CustomerService.dart';
- import 'Rule.dart';
- class LoginSecond extends StatefulWidget {
- LoginSecond({Key key, this.phone, this.userId = 0}) : super(key: key);
- final String phone; // 用来储存传递过来的值
- final int userId;
- @override
- LoginSecondState createState() => LoginSecondState();
- }
- class LoginSecondState extends State<LoginSecond> {
- String _sessionID;
- bool isSend = false; //是否发送
- int sendTime = 0;
- String password;
- String surePass;
- String useToken;
- Timer timer;
- String _qq;
- @override
- void initState() {
- super.initState();
- Future.delayed(Duration.zero, () async {
- // sendMsg();
- Result res2 = await HttpManager.get('customerService/random');
- if (res2.success) {
- setState(() {
- _qq = CustomerService.fromJson(res2.data).qq;
- });
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return WillPopScope(
- child: Container(
- color: BG_SUB_COLOR,
- child: Scaffold(
- appBar: AppBar(
- // backgroundColor: BG_SUB_COLOR,
- centerTitle: true,
- elevation: 0,
- ),
- body: Container(
- color: BG_SUB_COLOR,
- child: CustomScrollView(
- slivers: <Widget>[
- SliverToBoxAdapter(
- child: Container(
- color: BG_SUB_COLOR,
- padding: EdgeInsets.symmetric(vertical: 30, horizontal: 15),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- '请输入密码',
- style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w600),
- ),
- Container(
- height: widget.userId == 0 ? 5 : 20,
- ),
- widget.userId == 0
- ? Text(
- '您当前为首次登录,请设置您的密码',
- style: TextStyle(color: Colors.white, fontSize: 14),
- )
- : Container(),
- Container(
- margin: EdgeInsets.only(top: 10),
- child: ITextField(
- keyboardType: ITextInputType.password,
- prefixIcon: Container(
- padding: EdgeInsets.all(10),
- // color: PRIMARY_COLOR,
- child: Image.asset(
- 'images/list_icon_yanzhengma.png',
- width: 20,
- ),
- ),
- hintText: widget.userId == 0 ? '请设置您的密码' : '请输入您的密码',
- hintStyle: TextStyle(
- fontSize: 16,
- color: Color(0xFF727785),
- ),
- textStyle: TextStyle(color: Colors.white),
- fieldCallBack: (content) {
- setState(() {
- password = content;
- });
- },
- counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
- ),
- ),
- widget.userId == 0
- ? Container(
- margin: EdgeInsets.only(top: 10),
- child: ITextField(
- keyboardType: ITextInputType.password,
- prefixIcon: Container(
- padding: EdgeInsets.all(10),
- // color: PRIMARY_COLOR,
- child: Image.asset(
- 'images/list_icon_yanzhengma.png',
- width: 20,
- ),
- ),
- hintText: '请确认您的密码',
- hintStyle: TextStyle(
- fontSize: 16,
- color: Color(0xFF727785),
- ),
- textStyle: TextStyle(color: Colors.white),
- fieldCallBack: (content) {
- setState(() {
- surePass = content;
- });
- },
- counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
- ),
- )
- : Container(
- padding: EdgeInsetsDirectional.only(top: 10),
- child: InkWell(
- child: Text('忘记密码?',
- style: TextStyle(
- color: Theme.of(context).primaryColor,
- )),
- onTap: () {
- MyDialog.showDialog(context, '找回密码请联系客服',
- textList: [
- {'value': 'QQ:${_qq}', 'isImportant': false}
- ],
- title: '找回密码');
- },
- ),
- ),
- Container(
- height: 52,
- ),
- LinearButton(
- btntext: widget.userId == 0 ? '注册' : '登录',
- onTapHomeMenu: () async {
- print(password);
- if (password == '' || password == null) {
- Toast.show(context, '请输入密码', 1500, 'info');
- } else if (password != surePass && widget.userId == 0) {
- Toast.show(context, '两次密码输入不一致', 1500, 'info');
- } else {
- print(password);
- print(widget.phone);
- Toast.show(context, '加载中', -1, 'loading');
- final Result res =
- await HttpManager.post('auth/login', data: {'username': widget.phone, 'password': password, 'requireToken': true});
- Toast.hide();
- if (res.success) {
- final prefs = await SharedPreferences.getInstance();
- await prefs.setString('token', res.token);
- HttpManager.token = res.token;
- StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
- Toast.show(context, '登录成功', 1500, 'success');
- Navigator.pushReplacement(
- context,
- CupertinoPageRoute(builder: (context) => HomePage()),
- );
- } else {
- Toast.show(context, res.error, 1500, 'info');
- }
- }
- },
- ),
- Container(
- padding: EdgeInsetsDirectional.only(top: 40),
- child: Center(
- child: InkWell(
- child: Text('注册/登录即同意用户隐私协议', style: TextStyle(color: Theme.of(context).primaryColor, fontSize: 12)),
- onTap: () {
- Navigator.push(
- context,
- CupertinoPageRoute(builder: (context) => Rule()),
- );
- },
- ),
- ),
- ),
- ],
- ),
- ),
- )
- ],
- ),
- )),
- ),
- onWillPop: () {
- Toast.hide();
- Navigator.pop(context);
- return Future.value(false);
- });
- }
- Future<void> sendMsg() async {
- Toast.show(context, '加载中', -1, 'loading');
- final Result res = await HttpManager.get('rong/sendCode', data: {'phone': widget.phone});
- Toast.hide();
- if (res.success) {
- Toast.show(context, '发送成功', 1500, 'success');
- _sessionID = res.data;
- setState(() {
- isSend = true;
- });
- sendTime = 60;
- timer = Timer.periodic(Duration(seconds: 1), (timer) {
- if (sendTime == 0) {
- setState(() {
- isSend = false;
- });
- } else {
- setState(() {
- sendTime = sendTime - 1;
- });
- }
- });
- } else {
- Toast.show(context, res.error, 1500, 'info');
- }
- }
- }
|