优化 demo

This commit is contained in:
Cody
2026-03-08 21:13:48 +08:00
parent c310ded32a
commit 9610c455ec
7 changed files with 59 additions and 53 deletions

View File

@@ -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,
);
}

View File

@@ -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

View File

@@ -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),