Skip to content

Commit c5a3cf9

Browse files
committed
use relative path for theme assets
(cherry picked from commit 87ed25b)
1 parent 3307bc2 commit c5a3cf9

36 files changed

Lines changed: 1973 additions & 1495 deletions

lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void main() async {
156156
await Hive.openBox<dynamic>(DB.boxNamePrefs);
157157
await Prefs.instance.init();
158158

159+
await StackFileSystem.initThemesDir();
160+
159161
// Desktop migrate handled elsewhere (currently desktop_login_view.dart)
160162
if (!Util.isDesktop) {
161163
int dbVersion = DB.instance.get<dynamic>(
@@ -291,7 +293,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
291293
}
292294

293295
ref.read(applicationThemesDirectoryPathProvider.notifier).state =
294-
(await StackFileSystem.applicationThemesDirectory()).path;
296+
StackFileSystem.themesDir!.path;
295297

296298
_notificationsService = ref.read(notificationsProvider);
297299
_nodeService = ref.read(nodeServiceChangeNotifierProvider);
@@ -386,7 +388,7 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
386388
WidgetsBinding.instance.addPostFrameCallback((_) async {
387389
//Add themes path to provider
388390
ref.read(applicationThemesDirectoryPathProvider.notifier).state =
389-
(await StackFileSystem.applicationThemesDirectory()).path;
391+
StackFileSystem.themesDir!.path;
390392

391393
ref.read(themeProvider.state).state = ref.read(pThemeService).getTheme(
392394
themeId: themeId,

lib/models/isar/stack_theme.dart

Lines changed: 231 additions & 200 deletions
Large diffs are not rendered by default.

lib/models/isar/stack_theme.g.dart

Lines changed: 300 additions & 283 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pages/settings_views/global_settings_view/appearance_settings/sub_widgets/stack_theme_card.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class _StackThemeCardState extends ConsumerState<StackThemeCard> {
116116
}
117117

118118
Future<String> getThemeDirectorySize() async {
119-
final themesDir = await StackFileSystem.applicationThemesDirectory();
119+
final themesDir = StackFileSystem.themesDir!;
120120
final themeDir = Directory("${themesDir.path}/${widget.data.id}");
121121
int bytes = 0;
122122
if (await themeDir.exists()) {

lib/themes/theme_service.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ThemeService {
3030
void init(MainDB db) => _db ??= db;
3131

3232
Future<void> install({required Uint8List themeArchiveData}) async {
33-
final themesDir = await StackFileSystem.applicationThemesDirectory();
33+
final themesDir = StackFileSystem.themesDir!;
3434

3535
final archive = ZipDecoder().decodeBytes(themeArchiveData);
3636

@@ -45,7 +45,6 @@ class ThemeService {
4545

4646
final theme = StackTheme.fromJson(
4747
json: Map<String, dynamic>.from(json),
48-
applicationThemesDirectoryPath: themesDir.path,
4948
);
5049

5150
try {
@@ -78,7 +77,7 @@ class ThemeService {
7877
}
7978

8079
Future<void> remove({required String themeId}) async {
81-
final themesDir = await StackFileSystem.applicationThemesDirectory();
80+
final themesDir = StackFileSystem.themesDir!;
8281
final isarId = await db.isar.stackThemes
8382
.where()
8483
.themeIdEqualTo(themeId)
@@ -175,7 +174,7 @@ class ThemeService {
175174
return false;
176175
}
177176

178-
final themesDir = await StackFileSystem.applicationThemesDirectory();
177+
final themesDir = StackFileSystem.themesDir!;
179178
final jsonFileExists =
180179
await File("${themesDir.path}/$themeId/theme.json").exists();
181180
final assetsDirExists =

lib/utilities/stack_file_system.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ abstract class StackFileSystem {
6363
}
6464
}
6565

66-
static Future<Directory> applicationThemesDirectory() async {
66+
static Future<void> initThemesDir() async {
6767
final root = await applicationRootDirectory();
68-
// if (Util.isDesktop) {
68+
6969
final dir = Directory("${root.path}/themes");
7070
if (!dir.existsSync()) {
7171
await dir.create();
7272
}
73-
return dir;
74-
// } else {
75-
// return root;
76-
// }
73+
themesDir = dir;
7774
}
75+
76+
static Directory? themesDir;
7877
}
Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,71 @@
1-
// import 'package:flutter/material.dart';
2-
// import 'package:flutter_svg/svg.dart';
3-
// import 'package:flutter_test/flutter_test.dart';
4-
// import 'package:stackduo/models/notification_model.dart';
5-
// import 'package:stackduo/notifications/notification_card.dart';
6-
// import 'package:stackduo/utilities/assets.dart';
7-
// import 'package:stackduo/utilities/enums/coin_enum.dart';
8-
// import 'package:stackduo/utilities/theme/light_colors.dart';
9-
// import 'package:stackduo/utilities/theme/stack_colors.dart';
10-
//
11-
// void main() {
12-
// testWidgets("test notification card", (widgetTester) async {
13-
// final key = UniqueKey();
14-
// final notificationCard = NotificationCard(
15-
// key: key,
16-
// notification: NotificationModel(
17-
// id: 1,
18-
// title: "notification title",
19-
// description: "notification description",
20-
// iconAssetName: Assets.svg.iconFor(coin: Coin.bitcoin),
21-
// date: DateTime.parse("1662544771"),
22-
// walletId: "wallet id",
23-
// read: true,
24-
// shouldWatchForUpdates: true,
25-
// coinName: "Bitcoin"),
26-
// );
27-
//
28-
// await widgetTester.pumpWidget(
29-
// MaterialApp(
30-
// theme: ThemeData(
31-
// extensions: [
32-
// StackColors.fromStackColorTheme(LightColors()),
33-
// ],
34-
// ),
35-
// home: Material(
36-
// child: notificationCard,
37-
// ),
38-
// ),
39-
// );
40-
//
41-
// expect(find.byWidget(notificationCard), findsOneWidget);
42-
// expect(find.text("notification title"), findsOneWidget);
43-
// expect(find.text("notification description"), findsOneWidget);
44-
// expect(find.byType(SvgPicture), findsOneWidget);
45-
// });
46-
// }
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
import 'package:flutter_svg/svg.dart';
4+
import 'package:flutter_test/flutter_test.dart';
5+
import 'package:mockito/annotations.dart';
6+
import 'package:mockito/mockito.dart';
7+
import 'package:stackwallet/models/isar/stack_theme.dart';
8+
import 'package:stackwallet/models/notification_model.dart';
9+
import 'package:stackwallet/notifications/notification_card.dart';
10+
import 'package:stackwallet/themes/stack_colors.dart';
11+
import 'package:stackwallet/themes/theme_service.dart';
12+
import 'package:stackwallet/utilities/assets.dart';
13+
14+
import '../sample_data/theme_json.dart';
15+
import 'notification_card_test.mocks.dart';
16+
17+
@GenerateMocks([
18+
ThemeService,
19+
])
20+
void main() {
21+
testWidgets("test notification card", (widgetTester) async {
22+
final key = UniqueKey();
23+
final mockThemeService = MockThemeService();
24+
final theme = StackTheme.fromJson(
25+
json: lightThemeJsonMap,
26+
);
27+
28+
when(mockThemeService.getTheme(themeId: "light")).thenAnswer(
29+
(_) => theme,
30+
);
31+
32+
final notificationCard = NotificationCard(
33+
key: key,
34+
notification: NotificationModel(
35+
id: 1,
36+
title: "notification title",
37+
description: "notification description",
38+
iconAssetName: Assets.svg.plus,
39+
date: DateTime.parse("1662544771"),
40+
walletId: "wallet id",
41+
read: true,
42+
shouldWatchForUpdates: true,
43+
coinName: "Bitcoin"),
44+
);
45+
46+
await widgetTester.pumpWidget(
47+
ProviderScope(
48+
overrides: [
49+
pThemeService.overrideWithValue(mockThemeService),
50+
],
51+
child: MaterialApp(
52+
theme: ThemeData(
53+
extensions: [
54+
StackColors.fromStackColorTheme(
55+
theme,
56+
),
57+
],
58+
),
59+
home: Material(
60+
child: notificationCard,
61+
),
62+
),
63+
),
64+
);
65+
66+
expect(find.byWidget(notificationCard), findsOneWidget);
67+
expect(find.text("notification title"), findsOneWidget);
68+
expect(find.text("notification description"), findsOneWidget);
69+
expect(find.byType(SvgPicture), findsOneWidget);
70+
});
71+
}

0 commit comments

Comments
 (0)