-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap_screen.dart
More file actions
69 lines (59 loc) · 1.77 KB
/
bootstrap_screen.dart
File metadata and controls
69 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'package:androidircx/core/storage/shared_prefs_network_repository.dart';
import 'package:androidircx/features/chat/application/session_registry.dart';
import 'package:androidircx/features/connections/application/network_list_controller.dart';
import 'package:androidircx/features/connections/presentation/network_list_screen.dart';
import 'package:flutter/material.dart';
class BootstrapScreen extends StatefulWidget {
const BootstrapScreen({super.key});
@override
State<BootstrapScreen> createState() => _BootstrapScreenState();
}
class _BootstrapScreenState extends State<BootstrapScreen> {
late final NetworkListController _controller;
late final SessionRegistry _sessionRegistry;
bool _bootstrapComplete = false;
@override
void initState() {
super.initState();
_sessionRegistry = SessionRegistry();
_controller = NetworkListController(
repository: SharedPrefsNetworkRepository(),
);
_bootstrap();
}
Future<void> _bootstrap() async {
await _controller.load();
for (final network in _controller.networks.where((item) => item.autoConnect)) {
final session = _sessionRegistry.obtainSession(network);
await session.start();
}
if (!mounted) {
return;
}
setState(() {
_bootstrapComplete = true;
});
}
@override
void dispose() {
_controller.dispose();
_sessionRegistry.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!_bootstrapComplete && _controller.isLoading) {
return const Scaffold(
body: SafeArea(
child: Center(
child: CircularProgressIndicator(),
),
),
);
}
return NetworkListScreen(
controller: _controller,
sessionRegistry: _sessionRegistry,
);
}
}