Skip to content

Commit

Permalink
feat: add ModuleJsonable
Browse files Browse the repository at this point in the history
  • Loading branch information
foxsofter committed Sep 4, 2023
1 parent 8537157 commit 73aa0a3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 4.6.0
- feat: add ModuleJsonable

## 4.5.3
- fix: StreamTransfer type error

Expand Down
46 changes: 46 additions & 0 deletions lib/src/module/module_jsonable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// The MIT License (MIT)
//
// Copyright (c) 2020 foxsofter
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

import 'package:flutter/foundation.dart';
import 'package:flutter_jsonable/flutter_jsonable.dart';

import 'thrio_module.dart';

mixin ModuleJsonable on ThrioModule {
/// Get jsonable by type string.
///
@protected
Jsonable<dynamic>? getJsonable(final String typeString) =>
jsonableRegistry.getByTypeName(typeString);

/// A function for register a jsonable.
///
@protected
void onJsonableRegister(final ModuleContext moduleContext) {}

/// Register a jsonable.
///
/// Unregistry by calling the return value `VoidCallback`.
///
@protected
VoidCallback registerJsonSerializer<T>(final Jsonable<dynamic> jsonable) =>
jsonableRegistry.registerJsonable(jsonable);
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_thrio
description: Thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs.
version: 4.5.3
version: 4.6.0
homepage: https://github.com/flutter-thrio/flutter_thrio

environment:
Expand All @@ -11,6 +11,7 @@ dependencies:
flutter:
sdk: flutter
async: ^2.9.0
flutter_jsonable: ^1.0.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 73aa0a3

Please sign in to comment.