107 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Dart
		
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Dart
		
	
	
	
| 
 | |
| import 'package:common/utils/toast_utils.dart';
 | |
| import 'login_text_field_widget.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| import 'package:common/utils/widget_utils.dart';
 | |
| 
 | |
| 
 | |
| class LoginController{
 | |
| 
 | |
|   set name(String newText) {
 | |
|     if (nameChang != null){
 | |
|       nameChang!(newText);
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   Function(String name)? nameChang;
 | |
| 
 | |
|   set password(String newText) {
 | |
|     if (passwordChang != null){
 | |
|       passwordChang!(newText);
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   Function(String password)? passwordChang;
 | |
| 
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| class AccountNumberLoginWidget extends StatefulWidget {
 | |
|   const AccountNumberLoginWidget({Key? key, required this.loginTap, this.controller }) : super(key: key);
 | |
| 
 | |
|   final LoginController? controller;
 | |
|   final Function(String,String) loginTap;
 | |
| 
 | |
| 
 | |
|   @override
 | |
|   State<AccountNumberLoginWidget> createState() =>
 | |
|       _AccountNumberLoginWidgetState();
 | |
| }
 | |
| 
 | |
| class _AccountNumberLoginWidgetState extends State<AccountNumberLoginWidget> {
 | |
|   TextEditingController phoneController = TextEditingController();
 | |
|   TextEditingController passwordController = TextEditingController();
 | |
| 
 | |
| 
 | |
| 
 | |
|   _login() {
 | |
| 
 | |
|     if (phoneController.text.isEmpty || passwordController.text.isEmpty){
 | |
|       ToastUtils.showToast('请输入账号和密码');
 | |
|       return;
 | |
|     }
 | |
| 
 | |
|     widget.loginTap(phoneController.text,passwordController.text);
 | |
| 
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void initState()  {
 | |
|     super.initState();
 | |
| 
 | |
|     widget.controller?.nameChang = (name){
 | |
|       phoneController.text = name;
 | |
|     };
 | |
|     widget.controller?.passwordChang = (password){
 | |
|       passwordController.text = password;
 | |
|     };
 | |
| 
 | |
|   }
 | |
| 
 | |
|   
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     return Column(
 | |
|       mainAxisAlignment: MainAxisAlignment.center,
 | |
|       crossAxisAlignment: CrossAxisAlignment.stretch,
 | |
|       children: [
 | |
|         LoginPhoneTextField(controller: phoneController),
 | |
|         WidgetUtils.spacer(height: 15),
 | |
|         LoginPasswordTextField(controller: passwordController,onSubmitted: (_){
 | |
|           _login();
 | |
|         },),
 | |
|         WidgetUtils.spacer(height: 15),
 | |
|         TextButton(
 | |
|           onPressed: _login,
 | |
|           style: TextButton.styleFrom(padding: EdgeInsets.zero),
 | |
|           child: Container(
 | |
|             height: 40,
 | |
|             alignment: Alignment.center,
 | |
|             decoration: const BoxDecoration(
 | |
|                 color: Colors.blue,
 | |
|                 borderRadius: BorderRadius.all(Radius.circular(5))),
 | |
|             child: const Text(
 | |
|               '登录',
 | |
|               style: TextStyle(
 | |
|                 fontSize: 16,
 | |
|                 color: Colors.white,
 | |
|               ),
 | |
|             ),
 | |
|           ),
 | |
|         ),
 | |
|       ],
 | |
|     );
 | |
|   }
 | |
| }
 |