h-1.flutter.4/lib/screens/emergency_recovery_screen.dart

102 lines
No EOL
3.4 KiB
Dart

// EmergencyRecoveryScreen - 簡素化された緊急回復画面
import 'package:flutter/material.dart';
class EmergencyRecoveryScreen extends StatelessWidget {
final String errorMessage;
const EmergencyRecoveryScreen({super.key, this.errorMessage = ''});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.orange.shade50, Colors.yellow.shade50],
),
),
child: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Icon(
Icons.refresh,
size: 80,
color: Colors.deepOrange.shade600,
),
const SizedBox(height: 16),
Text(
'アプリの停止が発生しました',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.orange[700],
),
),
const SizedBox(height: 8),
Text(
errorMessage.isNotEmpty ? errorMessage : 'アプリが異常に停止しました。',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey[600]),
),
const SizedBox(height: 32),
ElevatedButton.icon(
icon: Icon(Icons.refresh),
label: Text('アプリを再起動'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
),
onPressed: () => _rebootApp(context),
),
],
),
),
),
),
),
);
}
Future<void> _rebootApp(BuildContext context) async {
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('アプリを再起動しますか?'),
content: Text(errorMessage.isNotEmpty ? errorMessage : 'アプリが正常に動作していないようです。再起動しますか?'),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('キャンセル')),
ElevatedButton(
onPressed: () {
if (context.mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
SystemNavigator.pop();
});
Navigator.pop(ctx, true);
}
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.blue.shade500),
child: const Text('再起動'),
),
],
),
);
if (confirmed == true) {
WidgetsBinding.instance.addPostFrameCallback((_) {
SystemNavigator.pop();
});
}
}
}