home_view.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'dart:io';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:naiyouwl/app/component/sys_app_bar.dart';
  6. import 'package:window_manager/window_manager.dart';
  7. import '../controllers/home_controller.dart';
  8. class HomeView extends GetView<HomeController> {
  9. const HomeView({Key? key}) : super(key: key);
  10. @override
  11. Widget build(BuildContext context) {
  12. return Container(
  13. decoration: const BoxDecoration(
  14. image: DecorationImage(
  15. image: AssetImage("images/login/login.png"),
  16. fit: BoxFit.fill,
  17. ),
  18. ),
  19. child: Scaffold(
  20. backgroundColor: Colors.transparent,
  21. appBar: const SysAppBar(title: Text("登录"),),
  22. body: LoginScreen(onLogin: (username,password) {
  23. // 在这里处理登录逻辑,例如调用API
  24. print('Username: $username');
  25. print('Password: $password');
  26. })
  27. ),
  28. );
  29. }
  30. }
  31. class LoginScreen extends StatefulWidget {
  32. final Function(String username, String password) onLogin;
  33. LoginScreen({required this.onLogin});
  34. @override
  35. _LoginScreenState createState() => _LoginScreenState();
  36. }
  37. class _LoginScreenState extends State<LoginScreen> {
  38. final _usernameController = TextEditingController();
  39. final _passwordController = TextEditingController();
  40. @override
  41. Widget build(BuildContext context) {
  42. return Padding(
  43. padding: const EdgeInsets.only(bottom: 30),
  44. child: Center(
  45. child: Padding(
  46. padding: const EdgeInsets.fromLTRB(55, 0, 55, 0),
  47. child: Column(
  48. mainAxisAlignment: MainAxisAlignment.center,
  49. children: [
  50. TextField(
  51. controller: _usernameController,
  52. decoration: const InputDecoration(
  53. labelText: '用户名',
  54. hintText: '请输入用户名',
  55. border: InputBorder.none,
  56. ),
  57. ),
  58. const SizedBox(height: 16),
  59. TextField(
  60. controller: _passwordController,
  61. decoration: const InputDecoration(
  62. labelText: '密码',
  63. hintText: '输入密码',
  64. border: InputBorder.none,
  65. ),
  66. obscureText: true,
  67. ),
  68. const SizedBox(height: 20),
  69. SizedBox(
  70. width: 200,
  71. height: 40,
  72. child: ElevatedButton(
  73. onPressed: () {
  74. final username = _usernameController.text;
  75. final password = _passwordController.text;
  76. widget.onLogin(username, password);
  77. },
  78. child: const Text('登录'),
  79. ),
  80. ),
  81. ],
  82. ),
  83. ),
  84. ),
  85. );
  86. }
  87. @override
  88. void dispose() {
  89. _usernameController.dispose();
  90. _passwordController.dispose();
  91. super.dispose();
  92. }
  93. }