fix:优化使用常用技术框架
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../../data/api/report_data_source.dart';
|
||||
import '../../../data/models/models.dart';
|
||||
@@ -151,7 +153,7 @@ class ModuleRendererRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleDetailPage extends StatefulWidget {
|
||||
class ModuleDetailPage extends HookConsumerWidget {
|
||||
const ModuleDetailPage({
|
||||
required this.reportId,
|
||||
required this.module,
|
||||
@@ -168,54 +170,67 @@ class ModuleDetailPage extends StatefulWidget {
|
||||
final ModuleRendererRegistry registry;
|
||||
|
||||
@override
|
||||
State<ModuleDetailPage> createState() => _ModuleDetailPageState();
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final retryCount = useState(0);
|
||||
final future = useMemoized(
|
||||
() => dataSource.moduleDetail(reportId, module.id),
|
||||
[dataSource, reportId, module.id, retryCount.value],
|
||||
);
|
||||
final snapshot = useFuture(future);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(module.titleCn)),
|
||||
body: snapshot.connectionState != ConnectionState.done
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: snapshot.hasError
|
||||
? Center(
|
||||
child: TextButton(
|
||||
onPressed: () => retryCount.value++,
|
||||
child: Text(
|
||||
snapshot.error.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
)
|
||||
: _ModuleDetailContent(
|
||||
detail: snapshot.data!,
|
||||
report: report,
|
||||
registry: registry,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ModuleDetailPageState extends State<ModuleDetailPage> {
|
||||
late Future<ModuleDetail> future = widget.dataSource.moduleDetail(
|
||||
widget.reportId,
|
||||
widget.module.id,
|
||||
);
|
||||
class _ModuleDetailContent extends StatelessWidget {
|
||||
const _ModuleDetailContent({
|
||||
required this.detail,
|
||||
required this.report,
|
||||
required this.registry,
|
||||
});
|
||||
|
||||
final ModuleDetail detail;
|
||||
final ReportDetail report;
|
||||
final ModuleRendererRegistry registry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.module.titleCn)),
|
||||
body: FutureBuilder<ModuleDetail>(
|
||||
future: future,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
snapshot.error.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
final detail = snapshot.data!;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
child: widget.registry.page(
|
||||
context,
|
||||
detail.type,
|
||||
detail.content,
|
||||
report: widget.report,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
'缓存版本 ${detail.cacheVersion}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(WiseSpacing.x4),
|
||||
children: [
|
||||
AppCard(
|
||||
child: registry.page(
|
||||
context,
|
||||
detail.type,
|
||||
detail.content,
|
||||
report: report,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: WiseSpacing.x3),
|
||||
Text(
|
||||
'缓存版本 ${detail.cacheVersion}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user