优化 demo
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// 数据库测试页状态(Demo,正式开发后随页面一并删除)
|
||||
|
||||
/// 单条测试结果记录
|
||||
class TestResult {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String duration;
|
||||
|
||||
TestResult({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.duration,
|
||||
});
|
||||
}
|
||||
|
||||
class ChatDbTestState {
|
||||
final bool testStarted;
|
||||
final List<TestResult> testResults;
|
||||
final String currentState;
|
||||
|
||||
const ChatDbTestState({
|
||||
this.testStarted = false,
|
||||
this.testResults = const [],
|
||||
this.currentState = '',
|
||||
});
|
||||
|
||||
/// 按钮文案(Widget 直接读,不在 View 层做判断)
|
||||
String get buttonLabel => testStarted ? '结束' : '开始';
|
||||
|
||||
ChatDbTestState copyWith({
|
||||
bool? testStarted,
|
||||
List<TestResult>? testResults,
|
||||
String? currentState,
|
||||
}) => ChatDbTestState(
|
||||
testStarted: testStarted ?? this.testStarted,
|
||||
testResults: testResults ?? this.testResults,
|
||||
currentState: currentState ?? this.currentState,
|
||||
);
|
||||
}
|
||||
@@ -6,42 +6,12 @@ import 'package:im_app/app/di/db_provider.dart';
|
||||
import 'package:im_app/data/local/drift/app_database.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'chat_db_test_state.dart';
|
||||
|
||||
export 'chat_db_test_state.dart';
|
||||
|
||||
part 'chat_db_test_view_model.g.dart';
|
||||
|
||||
class TestResult {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String duration;
|
||||
|
||||
TestResult({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.duration,
|
||||
});
|
||||
}
|
||||
|
||||
class ChatDbTestState {
|
||||
final bool testStarted;
|
||||
final List<TestResult> testResults;
|
||||
final String currentState;
|
||||
|
||||
const ChatDbTestState({
|
||||
this.testStarted = false,
|
||||
this.testResults = const [],
|
||||
this.currentState = '',
|
||||
});
|
||||
|
||||
ChatDbTestState copyWith({
|
||||
bool? testStarted,
|
||||
List<TestResult>? testResults,
|
||||
String? currentState,
|
||||
}) => ChatDbTestState(
|
||||
testStarted: testStarted ?? this.testStarted,
|
||||
testResults: testResults ?? this.testResults,
|
||||
currentState: currentState ?? this.currentState,
|
||||
);
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class ChatDbTestViewModel extends _$ChatDbTestViewModel {
|
||||
@override
|
||||
|
||||
@@ -30,7 +30,7 @@ class ChatDbTestPage extends ConsumerWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
AppButton.inverse(
|
||||
label: state.testStarted ? '结束' : '开始',
|
||||
label: state.buttonLabel,
|
||||
onPressed: () => vm.toggleDBTest(),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
|
||||
@@ -16,32 +16,27 @@ class ThemeView extends ConsumerWidget {
|
||||
final current = ref.watch(themeViewModelProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('主题'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('主题')),
|
||||
body: ListView(
|
||||
children: [
|
||||
const SettingsSectionHeader(title: '外观'),
|
||||
ThemeOptionTile(
|
||||
label: '跟随系统',
|
||||
mode: ThemeMode.system,
|
||||
current: current,
|
||||
isSelected: current == ThemeMode.system,
|
||||
onTap: () => ref
|
||||
.read(themeViewModelProvider.notifier)
|
||||
.setMode(ThemeMode.system),
|
||||
),
|
||||
ThemeOptionTile(
|
||||
label: '黑色模式',
|
||||
mode: ThemeMode.dark,
|
||||
current: current,
|
||||
isSelected: current == ThemeMode.dark,
|
||||
onTap: () => ref
|
||||
.read(themeViewModelProvider.notifier)
|
||||
.setMode(ThemeMode.dark),
|
||||
),
|
||||
ThemeOptionTile(
|
||||
label: '白色模式',
|
||||
mode: ThemeMode.light,
|
||||
current: current,
|
||||
isSelected: current == ThemeMode.light,
|
||||
onTap: () => ref
|
||||
.read(themeViewModelProvider.notifier)
|
||||
.setMode(ThemeMode.light),
|
||||
|
||||
@@ -5,14 +5,13 @@ import '../../../../../core/ui/base/context_theme_ext.dart';
|
||||
/// 单个主题选项行
|
||||
///
|
||||
/// 纯展示 + 事件透传,不感知任何 Provider。
|
||||
/// 由父级传入 [current] 判断选中状态,[onTap] 处理切换。
|
||||
/// 父级传入 [isSelected] 决定是否显示勾选图标,[onTap] 处理切换。
|
||||
///
|
||||
/// 用法:
|
||||
/// ```dart
|
||||
/// ThemeOptionTile(
|
||||
/// label: '黑色模式',
|
||||
/// mode: ThemeMode.dark,
|
||||
/// current: current,
|
||||
/// isSelected: current == ThemeMode.dark,
|
||||
/// onTap: () => ref.read(themeViewModelProvider.notifier).setMode(ThemeMode.dark),
|
||||
/// )
|
||||
/// ```
|
||||
@@ -20,20 +19,17 @@ class ThemeOptionTile extends StatelessWidget {
|
||||
const ThemeOptionTile({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.mode,
|
||||
required this.current,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final ThemeMode mode;
|
||||
final ThemeMode current;
|
||||
final bool isSelected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.styles;
|
||||
final isSelected = current == mode;
|
||||
|
||||
return ListTile(
|
||||
title: Text(label),
|
||||
|
||||
Reference in New Issue
Block a user