Extract BetaHome (2374 lines) to screens/home_screen.dart and LiveDiagnosticsDialog (97 lines) to screens/diagnostics_dialog.dart. main.dart reduced from 2910 to 255 lines. No behavioral changes.
98 lines
2.5 KiB
Dart
98 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
|
|
import '../l10n/generated/app_localizations.dart';
|
|
|
|
class LiveDiagnosticsDialog extends StatefulWidget {
|
|
const LiveDiagnosticsDialog({super.key, required this.diagnosticsTextBuilder});
|
|
|
|
final String Function() diagnosticsTextBuilder;
|
|
|
|
@override
|
|
State<LiveDiagnosticsDialog> createState() => _LiveDiagnosticsDialogState();
|
|
}
|
|
|
|
class _LiveDiagnosticsDialogState extends State<LiveDiagnosticsDialog> {
|
|
static const _refreshInterval = Duration(seconds: 1);
|
|
|
|
Timer? _refreshTimer;
|
|
String _text = '';
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_refresh();
|
|
_refreshTimer = Timer.periodic(_refreshInterval, (_) => _refresh());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_refreshTimer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
void _refresh() {
|
|
final next = widget.diagnosticsTextBuilder();
|
|
if (!mounted || next == _text) return;
|
|
setState(() => _text = next);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppL10n.of(context);
|
|
final size = MediaQuery.sizeOf(context);
|
|
|
|
return AlertDialog(
|
|
title: Row(
|
|
children: [
|
|
Expanded(child: Text(l10n.diagnosticsAction)),
|
|
const SizedBox(width: 12),
|
|
Tooltip(
|
|
message: l10n.diagnosticsLiveUpdating,
|
|
child: Icon(
|
|
Icons.sync,
|
|
size: 18,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
content: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxWidth: 720,
|
|
maxHeight: size.height * 0.65,
|
|
),
|
|
child: SingleChildScrollView(
|
|
child: SelectableText(
|
|
_text,
|
|
style: const TextStyle(fontFamily: 'monospace', fontSize: 11),
|
|
),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () async {
|
|
await SharePlus.instance.share(ShareParams(text: _text));
|
|
},
|
|
child: Text(l10n.shareAction),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
await Clipboard.setData(ClipboardData(text: _text));
|
|
if (!context.mounted) return;
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(l10n.copyAction),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text(l10n.closeAction),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|