Skip to content

Commit 5731164

Browse files
committed
Use: PKG Hive again and WASM workaround in Hive service, bump WASM build
1 parent eb95695 commit 5731164

File tree

7 files changed

+44
-26
lines changed

7 files changed

+44
-26
lines changed

.github/workflows/deploy_playground_netlify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
name: Deploy_Playground_Netlify
1616
on:
1717
push:
18-
branches: [none]
18+
branches: [master]
1919
paths-ignore:
2020
- "**.md"
2121
jobs:

example/lib/example5_themes_playground/utils/generate_theme_dart_code.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,11 +2367,11 @@ String generateThemeDartCode(ThemeController controller) {
23672367
'/// Use in [MaterialApp] like this:\n'
23682368
'///\n'
23692369
'/// MaterialApp(\n'
2370-
'/// theme: AppTheme.light,\n'
2371-
'/// darkTheme: AppTheme.dark,\n'
2372-
'/// :\n'
2370+
'/// theme: AppTheme.light,\n'
2371+
'/// darkTheme: AppTheme.dark,\n'
2372+
'/// :\n'
23732373
'/// );\n'
2374-
'sealed class AppTheme {\n'
2374+
'abstract final class AppTheme {\n'
23752375
' // The defined light theme.\n'
23762376
' static ThemeData light = FlexThemeData.light(\n'
23772377
'$lightScheme'

example/lib/example_copy_paste_from_playground/app_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
88
/// Use same major flex_color_scheme package version. If you use a
99
/// lower minor version, some properties may not be supported.
1010
/// In that case, remove them after copying this theme to your
11-
/// app or upgrade package to version 8.0.0-dev.1.
11+
/// app or upgrade package to version 8.0.2.
1212
///
1313
/// Use in [MaterialApp] like this:
1414
///
@@ -17,7 +17,7 @@ import 'package:flutter/material.dart';
1717
/// darkTheme: AppTheme.dark,
1818
/// :
1919
/// );
20-
sealed class AppTheme {
20+
abstract final class AppTheme {
2121
// The defined light theme.
2222
static ThemeData light = FlexThemeData.light(
2323
scheme: FlexScheme.sakura,

example/lib/shared/const/app.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ sealed class App {
4747
static const String versionMajor = '8';
4848
static const String versionMinor = '0';
4949
static const String versionPatch = '2';
50-
static const String versionBuild = '01';
50+
static const String versionBuild = '02';
5151
static const String versionFull = '$versionMajor.$versionMinor.$versionPatch'
5252
'\nBuild-$versionBuild';
5353
static const String version = '$versionMajor.$versionMinor.$versionPatch';
@@ -57,10 +57,9 @@ sealed class App {
5757
static const String author = 'Mike Rydstrom';
5858
static const String license = 'BSD 3-Clause License';
5959
static const String icon = 'assets/images/app_icon.png';
60+
static const String playgroundURL = 'https://playground.flexcolorscheme.com/';
6061
// static const String playgroundURL =
61-
// 'https://playground.flexcolorscheme.com/';
62-
static const String playgroundURL =
63-
'https://rydmike.com/flexcolorscheme/themesplayground-latest/';
62+
// 'https://rydmike.com/flexcolorscheme/themesplayground-latest/';
6463

6564
static final Uri packageUri = Uri(
6665
scheme: 'https',

example/lib/shared/services/theme_service_hive.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:hive_ce/hive.dart';
33

4+
import '../const/app.dart';
45
import '../utils/app_data_dir/app_data_dir.dart';
6+
import '../utils/same_types.dart';
57
import 'theme_service.dart';
68
import 'theme_service_hive_adapters.dart';
79

@@ -105,14 +107,32 @@ class ThemeServiceHive implements ThemeService {
105107
@override
106108
Future<T> load<T>(String key, T defaultValue) async {
107109
try {
108-
final dynamic value = _hiveBox.get(key, defaultValue: defaultValue);
110+
final dynamic value = await _hiveBox.get(key, defaultValue: defaultValue);
109111
if (_debug) {
110112
debugPrint('Hive LOAD _______________');
111-
debugPrint(' Type expected: $key as ${defaultValue.runtimeType}');
112-
debugPrint(' Type loaded : $key as ${value.runtimeType}');
113-
debugPrint(' Value loaded : $value');
113+
debugPrint(' Store key : $key');
114+
debugPrint(' Type expected : $T');
115+
debugPrint(' Stored value : $value');
116+
debugPrint(' Stored type : ${value.runtimeType}');
117+
debugPrint(' Default value : $defaultValue');
118+
debugPrint(' Default type : ${defaultValue.runtimeType}');
119+
}
120+
// Add workaround for Hive WASM returning double instead of int, when
121+
// values saved to IndexedDb were int.
122+
// See issue: https://github.com/IO-Design-Team/hive_ce/issues/46
123+
if (App.isRunningWithWasm &&
124+
value != null &&
125+
(value is double) &&
126+
(sameTypes<T, int?>() || sameTypes<T, int>())) {
127+
final T loaded = value.round() as T;
128+
if (_debug) {
129+
debugPrint(' ** WASM Issue : Expected int but got double, '
130+
'returning as int: $loaded');
131+
}
132+
return loaded;
133+
} else {
134+
return value as T;
114135
}
115-
return value as T;
116136
} catch (e) {
117137
debugPrint('Hive load (get) ERROR');
118138
debugPrint(' Error message ...... : $e');

example/pubspec.lock

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,10 @@ packages:
210210
hive_ce:
211211
dependency: "direct main"
212212
description:
213-
path: hive
214-
ref: main
215-
resolved-ref: f5d367b6c6b6a8a4bc3b23252e84353ab781197a
216-
url: "https://github.com/rydmike/hive_ce.git"
217-
source: git
213+
name: hive_ce
214+
sha256: "2d66fa89a3e33e6d95edcf6c75409cf8f6442ab46229c9baf423af479f532e99"
215+
url: "https://pub.dev"
216+
source: hosted
218217
version: "2.8.0+2"
219218
http:
220219
dependency: transitive

example/pubspec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ dependencies:
6868
# hive: ^2.2.3 # Original Hive package
6969
# This is a community fork that supports WASM-GC, by using package:web and
7070
# dart:js_interop.
71-
hive_ce: # ^2.8.0
71+
hive_ce: ^2.8.0
7272
#path: ../../hive_ce/hive
7373
# Temporarily used from a fixed fork until the official package is updated.
74-
git:
75-
url: https://github.com/rydmike/hive_ce.git
76-
ref: main
77-
path: hive/
74+
#git:
75+
# url: https://github.com/rydmike/hive_ce.git
76+
# ref: main
77+
# path: hive/
7878

7979
# Internationalization package, by Google dart.dev.
8080
# Used only for date time string formatting in example 5.

0 commit comments

Comments
 (0)