82 lines
3.1 KiB
Dart
82 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
|
||
import '../../../core/ui/components/app_button.dart';
|
||
import '../presentation/chat_view_model.dart';
|
||
|
||
/// 聊天页(Demo 按钮)
|
||
///
|
||
/// 包含五个演示按钮,覆盖 go_router 的常见导航场景:
|
||
/// - 「切换 Tab」 — go,替换历史,不可返回
|
||
/// - 「有参 push(extra)」 — push + extra(Dart Record),可返回
|
||
/// - 「有参 push(路径参数)」— push + URL 内嵌 id,可返回
|
||
/// - 「无参 push」 — push,可返回
|
||
/// - 「退出登录」 — 守卫自动重定向到 /login
|
||
///
|
||
/// 所有操作通过 [ChatViewModel] 处理,View 不直接调用路由。
|
||
/// 正式开发后替换为会话列表,按钮相关代码一并清除。
|
||
class ChatPage extends ConsumerWidget {
|
||
const ChatPage({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context, WidgetRef ref) {
|
||
return Scaffold(
|
||
appBar: AppBar(title: const Text('聊天')),
|
||
body: Center(
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
spacing: 16,
|
||
children: [
|
||
// 切换 Tab:用 go,替换整个历史栈,不可返回
|
||
AppButton.inverse(
|
||
label: '切换 Tab(go)',
|
||
onPressed: () =>
|
||
ref.read(chatViewModelProvider.notifier).goToContact(context),
|
||
),
|
||
// 带参数 push:extra 传 Dart Record,适合已有对象的场景
|
||
AppButton.inverse(
|
||
label: '有参 push(extra)',
|
||
onPressed: () => ref
|
||
.read(chatViewModelProvider.notifier)
|
||
.pushChatDetailWithExtra(context),
|
||
),
|
||
// 带参数 push:id 内嵌在路径中,适合需要深链接 / 分享的场景
|
||
AppButton.inverse(
|
||
label: '有参 push(路径参数)',
|
||
onPressed: () => ref
|
||
.read(chatViewModelProvider.notifier)
|
||
.pushChatDetailById(context),
|
||
),
|
||
// 无参 push:压栈,自动显示返回按钮,不切 Tab
|
||
AppButton.inverse(
|
||
label: '无参 push',
|
||
onPressed: () => ref
|
||
.read(chatViewModelProvider.notifier)
|
||
.pushSettingsTheme(context),
|
||
),
|
||
// 无参 go:替换历史,切换到对应 Tab,TabBar 可见,不可返回
|
||
AppButton.inverse(
|
||
label: '无参 go',
|
||
onPressed: () => ref
|
||
.read(chatViewModelProvider.notifier)
|
||
.goToSettings(context),
|
||
),
|
||
AppButton.inverse(
|
||
label: '测试数据库性能',
|
||
onPressed: () => ref
|
||
.read(chatViewModelProvider.notifier)
|
||
.goToDatabaseTest(context),
|
||
),
|
||
AppButton.secondary(
|
||
label: '退出登录',
|
||
fullWidth: false,
|
||
onPressed: () =>
|
||
ref.read(chatViewModelProvider.notifier).logout(),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|