Skip to content

Commit

Permalink
v6.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Nov 13, 2024
1 parent 60586d0 commit c5c3022
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [6.3.0] - 2024-11-13

* Update `updateState` to support RouteView paths
* Allow `NyPage` to support stateManaged methods using `bool get stateManaged => true;`
* Update pubspec.yaml

## [6.2.0] - 2024-11-10

* Override `build` in NyPage to support loading using a Scaffold
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ packages:
dependency: transitive
description:
name: flutter_local_notifications
sha256: "725145682706fb0e5a30f93e5cb64f3df7ed7743de749bd555b22bf75ee718c0"
sha256: ef41ae901e7529e52934feba19ed82827b11baa67336829564aeab3129460610
url: "https://pub.dev"
source: hosted
version: "18.0.0"
version: "18.0.1"
flutter_local_notifications_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -403,7 +403,7 @@ packages:
path: ".."
relative: true
source: path
version: "6.1.0"
version: "6.2.0"
path:
dependency: transitive
description:
Expand Down
15 changes: 13 additions & 2 deletions lib/helpers/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/services.dart';
import 'package:nylo_support/router/router.dart';
import '/event_bus/event_bus_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
Expand Down Expand Up @@ -348,7 +349,7 @@ void showNextLog() {
/// print(data); // 2
/// }
///
void updateState<T>(String name,
void updateState<T>(dynamic name,
{dynamic data, dynamic Function(T? currentValue)? setValue}) {
EventBus? eventBus = Backpack.instance.read("event_bus");
if (eventBus == null) {
Expand All @@ -369,7 +370,17 @@ void updateState<T>(String name,
}
}

final event = UpdateState(data: dataUpdate, stateName: name);
String stateName = '';
if (name is String) {
stateName = name;
}
if (name is RouteView) {
stateName =
"${name.$2.runtimeType.toString().replaceAll("BuildContext", "")}State"
.replaceAll("() => ", "() => _");
}

final event = UpdateState(data: dataUpdate, stateName: stateName);
eventBus.fire(event);
}

Expand Down
28 changes: 28 additions & 0 deletions lib/widgets/ny_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:skeletonizer/skeletonizer.dart';

import '../event_bus/res/history_entry.dart';
import '/nylo.dart';
import '/widgets/ny_base_state.dart';
import '/router/models/nyrouter_route_guard.dart';
import '/router/models/ny_argument.dart';
import 'package:flutter/material.dart';
import '/widgets/ny_stateful_widget.dart';
import 'event_bus/update_state.dart';

abstract class NyPage<T extends StatefulWidget> extends NyBaseState<T> {
/// Base NyPage
Expand All @@ -21,10 +23,36 @@ abstract class NyPage<T extends StatefulWidget> extends NyBaseState<T> {
return init is Future Function();
}

/// enable or disable if the [NyPage] should be state managed
bool get stateManaged => false;

@override
void initState() {
super.initState();

if (stateManaged) {
/// Set the state name if the widget is a NyStatefulWidget
if (widget is NyStatefulWidget) {
stateName = (widget as NyStatefulWidget).child.runtimeType.toString();
}

if (allowStateUpdates) {
List<EventBusHistoryEntry> eventHistory = eventBus!.history
.where((element) =>
element.event.runtimeType.toString() == 'UpdateState')
.toList();
if (eventHistory.isNotEmpty) {
stateData = eventHistory.last.event.props[1];
}
eventSubscription = eventBus!.on<UpdateState>().listen((event) async {
if (event.stateName != stateName) return;

await stateUpdated(event.data);
setState(() {});
});
}
}

if (widget is! NyStatefulWidget) {
if (!shouldLoadView) {
init();
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ packages:
dependency: "direct main"
description:
name: flutter_local_notifications
sha256: "725145682706fb0e5a30f93e5cb64f3df7ed7743de749bd555b22bf75ee718c0"
sha256: ef41ae901e7529e52934feba19ed82827b11baa67336829564aeab3129460610
url: "https://pub.dev"
source: hosted
version: "18.0.0"
version: "18.0.1"
flutter_local_notifications_linux:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: nylo_support
description: Support library for the Nylo framework. This library supports routing, widgets, localization, cli, storage and more.
version: 6.2.0
version: 6.3.0
homepage: https://nylo.dev
repository: https://github.com/nylo-core/support/tree/6.x
issue_tracker: https://github.com/nylo-core/support/issues
Expand Down Expand Up @@ -41,7 +41,7 @@ dependencies:
sdk: flutter
date_field: ^5.3.0
flutter_multi_formatter: ^2.13.0
flutter_local_notifications: ^18.0.0
flutter_local_notifications: ^18.0.1
path_provider: ^2.1.5
timezone: ^0.9.4
flutter_timezone: ^3.0.1
Expand Down

0 comments on commit c5c3022

Please sign in to comment.