#
whycq
2025-03-03 6a90c5bde0facc8330ce4c7c7d89292717b7ac65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:restart_app/restart_app.dart';
import '../../api/api_service.dart';
import '../../theme/theme_controller.dart';
import 'network_settings.dart';
import 'package:dio/dio.dart';
 
class LoginPage extends StatefulWidget {
  const LoginPage({super.key});
 
  @override
  State<LoginPage> createState() => _LoginPageState();
}
 
class _LoginPageState extends State<LoginPage> {
  final ThemeController themeController = Get.find();
  Dio dio =  Dio();
  String selectstr = "浅色";
 
  String _username = 'super';
  String _password = 'xltys2024';
 
 
 
 
  @override
  void initState() {
    super.initState();
  }
 
  // 登录按钮点击后的处理函数
  void _login() async {
    var res = await ApiService.login(_username,_password);
    if (res['code'] == 200) {
      Get.snackbar("登录成功", "欢迎回来!", duration: Duration(seconds: 2));
      Future.delayed(Duration(seconds: 2), () {
        Get.offNamed("/home_page");  // 1.导航到下一个页面
        // Get.offNamed("/home_page"); // 2.浏览并删除前一个页面
        // Get.offAllNamed("/home_page"); // 浏览并删除所有以前的页面
      });
    } else {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text(res['msg']),
            duration: Duration(seconds: 2),
            backgroundColor: Colors.red),
      );
 
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Login',
        ),
        backgroundColor: themeController.appBarColor,
        actions: [
          PopupMenuButton(
            onSelected: (String value) {
              print(value);
              // 处理选中的菜单项
              if (value == 'option1') {
                Get.to(NetworkSettings(), transition: Transition.rightToLeft);
              } else if (value == 'option2') {
                themeController.toggleTheme();
                Restart.restartApp();
              } else {}
 
              // Get.toNamed("/setting_network");
              print('Selected: $value');
            },
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(16),
            ),
            position: PopupMenuPosition.under,
            // 默认是over
            ///控制菜单的偏移位置,正值向右和下偏移,负值向左和上偏移
            offset: const Offset(-32, 0),
            onOpened: () => debugPrint('open'),
            onCanceled: () {
              debugPrint('cancel');
            },
            initialValue: 'two',
            itemBuilder: (BuildContext context) {
              return [
                PopupMenuItem(value: 'option1', child: Text('网络设置')),
                PopupMenuItem(value: 'option2', child: Text('颜色')),
                PopupMenuItem(value: 'option3', child: Text('其他')),
              ];
            },
          ),
        ],
      ),
      body: Center(
        child: ListView(
          children: [
            Container(
              child: Padding(
                padding:
                    EdgeInsets.only(left: 20, top: 100, right: 20, bottom: 100),
                child: Image(
                  image: AssetImage("lib/assets/images/newLogo.png"),
                  width: double.infinity,
                  height: 120.0,
                ),
              ),
            ),
            Container(
                child: Padding(
              padding: EdgeInsets.all(20),
              child: Column(
                children: [
                  TextField(
                    decoration: InputDecoration(
                        prefixIcon: Icon(Icons.phone_android),
                        hintText: '账号',
                        labelText: '账号',
                        // errorText: '请输入账号',
                        border: OutlineInputBorder()),
                    controller: TextEditingController(text: _username),
                    onChanged: (value) {
                      _username = value;
                    },
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  TextField(
                    obscureText: true,
                    decoration: InputDecoration(
                        prefixIcon: Icon(Icons.lock),
                        hintText: '密码',
                        labelText: '密码',
                        // errorText: '请输入账号',
                        border: OutlineInputBorder()),
                    controller: TextEditingController(text: _password),
                    onChanged: (value) {
                      _password = value;
                    },
                  ),
                ],
              ),
            )),
            Container(
              child: Padding(
                  padding: EdgeInsets.only(
                      left: 20, top: 100, right: 20, bottom: 100),
                  child: Center(
                    child: ElevatedButton(onPressed: _login, child: Text('登录')),
                  )),
            ),
          ],
        ),
      ),
    );
  }
}