Files
iroute/lib/v12/pages/login/login.dart
toly 7b16b52761 24
2023-12-10 15:25:12 +08:00

179 lines
5.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../components/components.dart';
import '../../app/authentication/auth_scope.dart';
import 'login_button.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const PreferredSize(
preferredSize: Size.fromHeight(46),
child: DragToMoveWrap(
child: Row(
children: [
SizedBox(
width: 20,
),
Text(
'欢迎登录',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
),
Spacer(),
WindowButtons()
],
),
),
),
body: Center(
child: SizedBox(
width: 360,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Login Page',
style: TextStyle(fontSize: 24),
),
const SizedBox(
height: 20,
),
buildUsernameInput(),
Stack(
alignment: const Alignment(.8, 0),
children: [
buildPasswordInput(),
GestureDetector(
onTap: () => setState(() => _showPwd = !_showPwd),
child: Icon(
_showPwd ? Icons.remove_red_eye : Icons.hide_source))
],
),
const SizedBox(
height: 20,
),
LoginButton(
onLogin: () async {
String username = _usernameController.text;
String pwd = _passwordController.text;
(bool, String) result = await AuthScope.read(context).login(username, pwd);
if (result.$1) {
context.go('/');
}else{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.redAccent,
content: Text(result.$2)));
}
},
)
],
),
),
),
);
}
final _usernameController = TextEditingController(text: '张风捷特烈');
final _passwordController = TextEditingController(text: '111111');
Widget buildUsernameInput() {
return Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey.withOpacity(0.5),
width: 1.0,
),
borderRadius: BorderRadius.circular(15.0),
),
margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
child: Row(
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),
child: Icon(
Icons.person_outline,
color: Colors.grey,
),
),
Container(
height: 20.0,
width: 1.0,
color: Colors.grey.withOpacity(0.5),
margin: const EdgeInsets.only(left: 00.0, right: 10.0),
),
Expanded(
child: TextField(
controller: _usernameController,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: '请输入用户名...',
hintStyle: TextStyle(color: Colors.grey),
),
),
)
],
),
)
],
);
}
bool _showPwd = false;
Widget buildPasswordInput() {
return Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey.withOpacity(0.5),
width: 1.0,
),
borderRadius: BorderRadius.circular(15.0),
),
margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
child: Row(
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),
child: Icon(
Icons.lock_outline,
color: Colors.grey,
),
),
Container(
height: 30.0,
width: 1.0,
color: Colors.grey.withOpacity(0.5),
margin: const EdgeInsets.only(left: 00.0, right: 10.0),
),
Expanded(
child: TextField(
obscureText: !_showPwd,
controller: _passwordController,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: '请输入密码...',
hintStyle: TextStyle(color: Colors.grey),
),
),
)
],
),
)
],
);
}
}