123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import 'dart:io';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:naiyouwl/app/component/sys_app_bar.dart';
- import 'package:window_manager/window_manager.dart';
- import '../controllers/home_controller.dart';
- class HomeView extends GetView<HomeController> {
- const HomeView({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- decoration: const BoxDecoration(
- image: DecorationImage(
- image: AssetImage("images/login/login.png"),
- fit: BoxFit.fill,
- ),
- ),
- child: Scaffold(
- backgroundColor: Colors.transparent,
- appBar: const SysAppBar(title: Text("登录"),),
- body: Obx(() {
- return LoginScreen(isLoading: controller.isLoading.value,
- onLogin: (username, password) {
- controller.fetchSysConfig();
- // 在这里处理登录逻辑,例如调用API
- print('Username: $username');
- print('Password: $password');
- });
- })
- ),
- );
- }
- }
- class LoginScreen extends StatefulWidget {
- final Function(String username, String password) onLogin;
- final bool isLoading;
- LoginScreen({required this.isLoading, required this.onLogin});
- @override
- _LoginScreenState createState() => _LoginScreenState();
- }
- class _LoginScreenState extends State<LoginScreen> {
- final _usernameController = TextEditingController();
- final _passwordController = TextEditingController();
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.only(bottom: 30),
- child: Center(
- child: Padding(
- padding: const EdgeInsets.fromLTRB(55, 0, 55, 0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- TextField(
- controller: _usernameController,
- decoration: const InputDecoration(
- labelText: '用户名',
- hintText: '请输入用户名',
- border: InputBorder.none,
- ),
- ),
- const SizedBox(height: 16),
- TextField(
- controller: _passwordController,
- decoration: const InputDecoration(
- labelText: '密码',
- hintText: '输入密码',
- border: InputBorder.none,
- ),
- obscureText: true,
- ),
- const SizedBox(height: 20),
- SizedBox(
- width: 200,
- height: 40,
- child: ElevatedButton(
- onPressed: () {
- if (!widget.isLoading) {
- final username = _usernameController.text;
- final password = _passwordController.text;
- widget.onLogin(username, password);
- }
- },
- child: widget.isLoading ? const CircularProgressIndicator(
- color: Colors.white,
- ) : const Text('登录'),
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- @override
- void dispose() {
- _usernameController.dispose();
- _passwordController.dispose();
- super.dispose();
- }
- }
|