2024-01-31 05:14:23 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-10-03 23:32:35 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-14 21:48:05 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-02-08 11:59:52 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2021-01-14 21:48:05 +00:00
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2021-01-18 10:21:55 +00:00
|
|
|
import 'package:selfprivacy/logic/models/message.dart';
|
2023-04-04 16:06:14 +00:00
|
|
|
import 'package:selfprivacy/ui/components/list_tiles/log_list_tile.dart';
|
2021-01-14 21:48:05 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2023-02-23 14:49:14 +00:00
|
|
|
class ConsolePage extends StatefulWidget {
|
|
|
|
const ConsolePage({super.key});
|
2021-01-14 21:48:05 +00:00
|
|
|
|
|
|
|
@override
|
2023-02-23 14:49:14 +00:00
|
|
|
State<ConsolePage> createState() => _ConsolePageState();
|
2021-01-14 21:48:05 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 14:49:14 +00:00
|
|
|
class _ConsolePageState extends State<ConsolePage> {
|
2024-02-08 11:59:52 +00:00
|
|
|
bool paused = false;
|
|
|
|
|
2021-01-14 21:48:05 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-02-08 11:59:52 +00:00
|
|
|
|
|
|
|
getIt<ConsoleModel>().addListener(update);
|
2021-01-14 21:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
getIt<ConsoleModel>().removeListener(update);
|
2024-02-08 11:59:52 +00:00
|
|
|
|
2021-01-14 21:48:05 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2023-04-04 16:06:14 +00:00
|
|
|
void update() {
|
2024-02-08 11:59:52 +00:00
|
|
|
/// listener update could come at any time, like when widget is already
|
|
|
|
/// unmounted or during frame build, adding as postframe callback ensures
|
|
|
|
/// that element is marked for rebuild
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((final _) {
|
|
|
|
if (!paused && mounted) {
|
|
|
|
setState(() => {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void togglePause() {
|
|
|
|
paused ^= true;
|
|
|
|
setState(() {});
|
2023-04-04 16:06:14 +00:00
|
|
|
}
|
2021-01-14 21:48:05 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) => SafeArea(
|
2022-06-05 22:40:34 +00:00
|
|
|
child: Scaffold(
|
2023-04-04 16:06:14 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('console_page.title'.tr()),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
2023-04-04 16:06:14 +00:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
2023-04-05 10:33:53 +00:00
|
|
|
icon: Icon(
|
2023-04-12 05:42:33 +00:00
|
|
|
paused ? Icons.play_arrow_outlined : Icons.pause_outlined,
|
|
|
|
),
|
2024-02-08 11:59:52 +00:00
|
|
|
onPressed: togglePause,
|
2023-04-04 16:06:14 +00:00
|
|
|
),
|
|
|
|
],
|
2021-01-14 21:48:05 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
body: FutureBuilder(
|
|
|
|
future: getIt.allReady(),
|
|
|
|
builder: (
|
|
|
|
final BuildContext context,
|
|
|
|
final AsyncSnapshot<void> snapshot,
|
|
|
|
) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final List<Message> messages =
|
|
|
|
getIt.get<ConsoleModel>().messages;
|
2021-01-14 21:48:05 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
return ListView(
|
|
|
|
reverse: true,
|
|
|
|
shrinkWrap: true,
|
|
|
|
children: [
|
2024-02-08 11:59:52 +00:00
|
|
|
const Gap(20),
|
|
|
|
...messages.reversed.map(
|
|
|
|
(final message) => LogListItem(
|
|
|
|
key: ValueKey(message),
|
|
|
|
message: message,
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2024-02-08 11:59:52 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2022-10-03 23:32:35 +00:00
|
|
|
children: [
|
|
|
|
Text('console_page.waiting'.tr()),
|
2024-02-08 11:59:52 +00:00
|
|
|
const Gap(16),
|
2024-03-13 15:20:50 +00:00
|
|
|
const CircularProgressIndicator.adaptive(),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2021-01-14 21:48:05 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
);
|
2021-01-14 21:48:05 +00:00
|
|
|
}
|