47 lines
1.7 KiB
Dart
47 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
|
||
import '../../../../core/ui/base/context_theme_ext.dart';
|
||
import '../presentation/login_view_model.dart';
|
||
|
||
/// 登录页(Demo)
|
||
///
|
||
/// 演示 go_router 登录守卫:点击「登录」后经由 [LoginViewModel.demoLogin]
|
||
/// 触发 [GoRouter.refreshListenable],守卫重新执行并重定向到 /chat。
|
||
///
|
||
/// 正式实现时替换为完整登录流程(email/password 输入 → LoginViewModel.login)。
|
||
class LoginPage extends ConsumerWidget {
|
||
const LoginPage({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
// ref.watch 保持 loginViewModelProvider 存活(AutoDispose 需要至少一个监听者)
|
||
final state = ref.watch(loginViewModelProvider);
|
||
final s = context.styles;
|
||
|
||
return Scaffold(
|
||
appBar: AppBar(title: const Text('登录'), automaticallyImplyLeading: false),
|
||
body: Center(
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Text('IM_Demo', style: s.titleMedium),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
'未登录时任意路由均被重定向到此页 \n 主要是为了展示路由守卫的功能 \n 后续路由守卫专门处理各种跳转前的逻辑判断',
|
||
style: s.bodySmall,
|
||
),
|
||
const SizedBox(height: 32),
|
||
FilledButton(
|
||
onPressed: state.isLoading
|
||
? null
|
||
: () => ref.read(loginViewModelProvider.notifier).demoLogin(),
|
||
child: const Text('登录'),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|