-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathalready_running_view.dart
More file actions
191 lines (180 loc) · 6.77 KB
/
already_running_view.dart
File metadata and controls
191 lines (180 loc) · 6.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart';
import '../app_config.dart';
import '../themes/stack_colors.dart';
import '../themes/theme_providers.dart';
import '../themes/theme_service.dart';
import '../utilities/stack_file_system.dart';
import '../utilities/text_styles.dart';
import '../utilities/util.dart';
import '../widgets/app_icon.dart';
import '../widgets/background.dart';
/// Root app widget for the "already running" error path.
///
/// Mirrors the theme bootstrap performed by [MaterialAppWithTheme] in main.dart
/// but without touching Hive. Requires Isar + ThemeService to already be
/// initialized before [runApp] is called.
class AlreadyRunningApp extends ConsumerStatefulWidget {
const AlreadyRunningApp({super.key});
@override
ConsumerState<AlreadyRunningApp> createState() => _AlreadyRunningAppState();
}
class _AlreadyRunningAppState extends ConsumerState<AlreadyRunningApp> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(applicationThemesDirectoryPathProvider.notifier).state =
StackFileSystem.themesDir!.path;
// The first instance already verified/installed the light theme, so
// getTheme cannot return null here.
ref.read(themeProvider.state).state = ref
.read(pThemeService)
.getTheme(themeId: "light")!;
});
}
@override
Widget build(BuildContext context) {
final colorScheme = ref.watch(colorProvider.state).state;
return MaterialApp(
debugShowCheckedModeBanner: false,
title: AppConfig.appName,
theme: ThemeData(
extensions: [colorScheme],
fontFamily: GoogleFonts.inter().fontFamily,
splashColor: Colors.transparent,
),
home: const AlreadyRunningView(),
);
}
}
/// Error screen shown when this is a second instance of the app.
///
/// Mirrors [IntroView]'s layout: themed background, logo, app name heading,
/// short description subtitle, then the error message (in label style, smaller
/// than the subtitle) in place of the action buttons.
class AlreadyRunningView extends ConsumerWidget {
const AlreadyRunningView({super.key});
static const _errorMessage =
"${AppConfig.appName} is already running. "
"Close the other window and try again.";
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDesktop = Util.isDesktop;
final colors = Theme.of(context).extension<StackColors>()!;
final stack = ref.watch(
themeProvider.select((value) => value.assets.stack),
);
return Background(
child: Scaffold(
backgroundColor: colors.background,
body: SafeArea(
child: Center(
child: !isDesktop
? Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Spacer(flex: 2),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: SizedBox(
width: 266,
height: 266,
child: stack.endsWith(".png")
? Image.file(File(stack))
: SvgPicture.file(
File(stack),
width: 266,
height: 266,
),
),
),
),
const Spacer(flex: 1),
Text(
AppConfig.appName,
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(context),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 48),
child: Text(
AppConfig.shortDescriptionText,
textAlign: TextAlign.center,
style: STextStyles.subtitle(context),
),
),
const Spacer(flex: 4),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
child: Text(
_errorMessage,
textAlign: TextAlign.center,
style: STextStyles.label(context),
),
),
],
)
: SizedBox(
width: 350,
height: 540,
child: Column(
children: [
const Spacer(flex: 2),
const SizedBox(
width: 130,
height: 130,
child: AppIcon(),
),
const Spacer(flex: 42),
Text(
AppConfig.appName,
textAlign: TextAlign.center,
style: STextStyles.pageTitleH1(
context,
).copyWith(fontSize: 40),
),
const Spacer(flex: 24),
Text(
AppConfig.shortDescriptionText,
textAlign: TextAlign.center,
style: STextStyles.subtitle(
context,
).copyWith(fontSize: 24),
),
const Spacer(flex: 42),
Text(
_errorMessage,
textAlign: TextAlign.center,
style: STextStyles.label(
context,
).copyWith(fontSize: 18),
),
const Spacer(flex: 65),
],
),
),
),
),
),
);
}
}