Skip to content

Commit

Permalink
Use: PKG Hive again and WASM workaround in Hive service, bump WASM build
Browse files Browse the repository at this point in the history
  • Loading branch information
rydmike committed Dec 6, 2024
1 parent eb95695 commit 5731164
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_playground_netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: Deploy_Playground_Netlify
on:
push:
branches: [none]
branches: [master]
paths-ignore:
- "**.md"
jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2367,11 +2367,11 @@ String generateThemeDartCode(ThemeController controller) {
'/// Use in [MaterialApp] like this:\n'
'///\n'
'/// MaterialApp(\n'
'/// theme: AppTheme.light,\n'
'/// darkTheme: AppTheme.dark,\n'
'/// :\n'
'/// theme: AppTheme.light,\n'
'/// darkTheme: AppTheme.dark,\n'
'/// :\n'
'/// );\n'
'sealed class AppTheme {\n'
'abstract final class AppTheme {\n'
' // The defined light theme.\n'
' static ThemeData light = FlexThemeData.light(\n'
'$lightScheme'
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example_copy_paste_from_playground/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
/// Use same major flex_color_scheme package version. If you use a
/// lower minor version, some properties may not be supported.
/// In that case, remove them after copying this theme to your
/// app or upgrade package to version 8.0.0-dev.1.
/// app or upgrade package to version 8.0.2.
///
/// Use in [MaterialApp] like this:
///
Expand All @@ -17,7 +17,7 @@ import 'package:flutter/material.dart';
/// darkTheme: AppTheme.dark,
/// :
/// );
sealed class AppTheme {
abstract final class AppTheme {
// The defined light theme.
static ThemeData light = FlexThemeData.light(
scheme: FlexScheme.sakura,
Expand Down
7 changes: 3 additions & 4 deletions example/lib/shared/const/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sealed class App {
static const String versionMajor = '8';
static const String versionMinor = '0';
static const String versionPatch = '2';
static const String versionBuild = '01';
static const String versionBuild = '02';
static const String versionFull = '$versionMajor.$versionMinor.$versionPatch'
'\nBuild-$versionBuild';
static const String version = '$versionMajor.$versionMinor.$versionPatch';
Expand All @@ -57,10 +57,9 @@ sealed class App {
static const String author = 'Mike Rydstrom';
static const String license = 'BSD 3-Clause License';
static const String icon = 'assets/images/app_icon.png';
static const String playgroundURL = 'https://playground.flexcolorscheme.com/';
// static const String playgroundURL =
// 'https://playground.flexcolorscheme.com/';
static const String playgroundURL =
'https://rydmike.com/flexcolorscheme/themesplayground-latest/';
// 'https://rydmike.com/flexcolorscheme/themesplayground-latest/';

static final Uri packageUri = Uri(
scheme: 'https',
Expand Down
30 changes: 25 additions & 5 deletions example/lib/shared/services/theme_service_hive.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:hive_ce/hive.dart';

import '../const/app.dart';
import '../utils/app_data_dir/app_data_dir.dart';
import '../utils/same_types.dart';
import 'theme_service.dart';
import 'theme_service_hive_adapters.dart';

Expand Down Expand Up @@ -105,14 +107,32 @@ class ThemeServiceHive implements ThemeService {
@override
Future<T> load<T>(String key, T defaultValue) async {
try {
final dynamic value = _hiveBox.get(key, defaultValue: defaultValue);
final dynamic value = await _hiveBox.get(key, defaultValue: defaultValue);
if (_debug) {
debugPrint('Hive LOAD _______________');
debugPrint(' Type expected: $key as ${defaultValue.runtimeType}');
debugPrint(' Type loaded : $key as ${value.runtimeType}');
debugPrint(' Value loaded : $value');
debugPrint(' Store key : $key');
debugPrint(' Type expected : $T');
debugPrint(' Stored value : $value');
debugPrint(' Stored type : ${value.runtimeType}');
debugPrint(' Default value : $defaultValue');
debugPrint(' Default type : ${defaultValue.runtimeType}');
}
// Add workaround for Hive WASM returning double instead of int, when
// values saved to IndexedDb were int.
// See issue: https://github.com/IO-Design-Team/hive_ce/issues/46
if (App.isRunningWithWasm &&
value != null &&
(value is double) &&
(sameTypes<T, int?>() || sameTypes<T, int>())) {
final T loaded = value.round() as T;
if (_debug) {
debugPrint(' ** WASM Issue : Expected int but got double, '
'returning as int: $loaded');
}
return loaded;
} else {
return value as T;
}
return value as T;
} catch (e) {
debugPrint('Hive load (get) ERROR');
debugPrint(' Error message ...... : $e');
Expand Down
9 changes: 4 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,10 @@ packages:
hive_ce:
dependency: "direct main"
description:
path: hive
ref: main
resolved-ref: f5d367b6c6b6a8a4bc3b23252e84353ab781197a
url: "https://github.com/rydmike/hive_ce.git"
source: git
name: hive_ce
sha256: "2d66fa89a3e33e6d95edcf6c75409cf8f6442ab46229c9baf423af479f532e99"
url: "https://pub.dev"
source: hosted
version: "2.8.0+2"
http:
dependency: transitive
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ dependencies:
# hive: ^2.2.3 # Original Hive package
# This is a community fork that supports WASM-GC, by using package:web and
# dart:js_interop.
hive_ce: # ^2.8.0
hive_ce: ^2.8.0
#path: ../../hive_ce/hive
# Temporarily used from a fixed fork until the official package is updated.
git:
url: https://github.com/rydmike/hive_ce.git
ref: main
path: hive/
#git:
# url: https://github.com/rydmike/hive_ce.git
# ref: main
# path: hive/

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

1 comment on commit 5731164

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.