Skip to content

Commit

Permalink
v6.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agordn52 committed Jan 12, 2025
1 parent 9af92be commit de840ec
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 61 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [6.15.0] - 2025-01-12

* Make `updatePageState` public
* Ensure `handleSuccess` handles responses within the correct status code range. Fixes [207](https://github.com/nylo-core/nylo/issues/207)
* Fix `header` parameter in NyPullToRefresh and NyListView
* Small fix for NyForm
* Improvements to NavigationHub to support Text tabs and Icons
* Updates to `NavigationTab` to support updating the Page, Title, Icon, Background Color and Tooltip
* Update pubspec.yaml

## [6.14.4] - 2025-01-06

* Fix issue with `NyState`
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ packages:
dependency: transitive
description:
name: flutter_secure_storage
sha256: "1913841ac4c7bf57cd2e05b717e1fbff7841b542962feff827b16525a781b3e4"
sha256: "9cad52d75ebc511adfae3d447d5d13da15a55a92c9410e50f67335b6d21d16ea"
url: "https://pub.dev"
source: hosted
version: "9.2.3"
version: "9.2.4"
flutter_secure_storage_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -584,10 +584,10 @@ packages:
dependency: transitive
description:
name: skeletonizer
sha256: "3b202e4fa9c49b017d368fb0e570d4952bcd19972b67b2face071bdd68abbfae"
sha256: "0dcacc51c144af4edaf37672072156f49e47036becbc394d7c51850c5c1e884b"
url: "https://pub.dev"
source: hosted
version: "1.4.2"
version: "1.4.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class BaseController {

/// Returns any data passed through a [Navigator] or [routeTo] method.
T? data<T>({dynamic defaultValue}) =>
request?.data(defaultValue: defaultValue);
request?.data(defaultValue: defaultValue) ?? defaultValue;

/// Returns any query parameters passed in a route
/// e.g. /my-page?hello=world
Expand Down
30 changes: 15 additions & 15 deletions lib/controllers/ny_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ class NyController extends BaseController {

/// Updates the page [state]
/// Provide an [action] and [data] to call a method in the [NyState].
void _updatePageState(String action, dynamic data) {
void updatePageState(String action, dynamic data) {
assert(state != null, "State cannot be null");
if (state == null) return;
updateState(state!, data: {"action": action, "data": data});
}

/// Refreshes the page
refreshPage() {
_updatePageState("refresh-page", {"setState": () {}});
updatePageState("refresh-page", {"setState": () {}});
}

/// Set the state of the page
setState({required Function() setState}) {
_updatePageState("set-state", {"setState": setState});
updatePageState("set-state", {"setState": setState});
}

/// Pop the page
pop({dynamic result}) {
_updatePageState("pop", {"result": result});
updatePageState("pop", {"result": result});
}

/// Displays a Toast message containing "Sorry" for the title, you
Expand All @@ -38,7 +38,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-sorry", {
updatePageState("toast-sorry", {
"title": title ?? "Sorry",
"description": description,
"style": style ?? ToastNotificationStyleType.danger
Expand All @@ -51,7 +51,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-warning", {
updatePageState("toast-warning", {
"title": title ?? "Warning",
"description": description,
"style": style ?? ToastNotificationStyleType.warning
Expand All @@ -64,7 +64,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-info", {
updatePageState("toast-info", {
"title": title ?? "Info",
"description": description,
"style": style ?? ToastNotificationStyleType.info
Expand All @@ -77,7 +77,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-danger", {
updatePageState("toast-danger", {
"title": title ?? "Error",
"description": description,
"style": style ?? ToastNotificationStyleType.danger
Expand All @@ -90,7 +90,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-oops", {
updatePageState("toast-oops", {
"title": title ?? "Oops",
"description": description,
"style": style ?? ToastNotificationStyleType.danger
Expand All @@ -103,7 +103,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-success", {
updatePageState("toast-success", {
"title": title ?? "Success",
"description": description,
"style": style ?? ToastNotificationStyleType.success
Expand All @@ -115,7 +115,7 @@ class NyController extends BaseController {
{String? title,
required String description,
ToastNotificationStyleType? style}) {
_updatePageState("toast-custom", {
updatePageState("toast-custom", {
"title": title ?? "",
"description": description,
"style": style ?? ToastNotificationStyleType.custom
Expand All @@ -134,7 +134,7 @@ class NyController extends BaseController {
required Function()? onSuccess,
Function(Exception exception)? onFailure,
String? lockRelease}) {
_updatePageState("validate", {
updatePageState("validate", {
"rules": rules,
"data": data,
"messages": messages,
Expand All @@ -149,7 +149,7 @@ class NyController extends BaseController {

/// Update the language in the application
void changeLanguage(String language, {bool restartState = true}) {
_updatePageState("change-language", {
updatePageState("change-language", {
"language": language,
"restartState": restartState,
});
Expand All @@ -158,14 +158,14 @@ class NyController extends BaseController {
/// Perform a lock release
void lockRelease(String name,
{required Function perform, bool shouldSetState = true}) async {
_updatePageState("lock-release",
updatePageState("lock-release",
{"name": name, "perform": perform, "shouldSetState": shouldSetState});
}

/// Perform a confirm action
void confirmAction(Function() action,
{required String title, String dismissText = "Cancel"}) async {
_updatePageState("confirm-action",
updatePageState("confirm-action",
{"action": action, "title": title, "dismissText": dismissText});
}
}
6 changes: 5 additions & 1 deletion lib/networking/dio_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ class DioApiService {
/// You can return a different value using this callback.
handleResponse<T>(Response response,
{Function(Response response)? handleSuccess}) {
bool wasSuccessful = response.statusCode == 200;
bool wasSuccessful = false;
if (response.statusCode != null) {
wasSuccessful =
(response.statusCode!) >= 200 && (response.statusCode!) < 300;
}

if (wasSuccessful == true && handleSuccess != null) {
return handleSuccess(response);
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/form/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class _NyFormState extends NyState<NyForm> {

@override
get init => () {
if (widget.form.updated?.hasListener ?? false) {
widget.form.updated?.close();
}

widget.form.updated?.stream.listen((data) {
String fieldSnakeCase = ReCase(data.$1).snakeCase;
dynamic formData = widget.form.data(lowerCaseKeys: true);
Expand Down
20 changes: 10 additions & 10 deletions lib/widgets/navigation_hub/badge_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BadgeTab extends StatefulWidget {
const BadgeTab(
{super.key,
required this.state,
required this.icon,
this.icon,
this.initialCount,
this.backgroundColor,
this.textColor,
Expand All @@ -25,10 +25,7 @@ class BadgeTab extends StatefulWidget {

/// Create a BadgeTab from a NavigationTab
BadgeTab.fromNavigationTab(NavigationTab page,
{super.key,
required Widget this.icon,
required int index,
String? stateName})
{super.key, required int index, this.icon, String? stateName})
: state = (stateName ?? "${page.title}_navigation_tab_$index"),
initialCount = page.meta['initialCount'],
rememberCount = page.meta['rememberCount'],
Expand Down Expand Up @@ -85,14 +82,14 @@ class _BadgeTabState extends NyState<BadgeTab> {
await NyStorage.save(stateName!, currentCount);
}
}
if (stateData != null) {
if (stateData != null && stateData is int) {
currentCount = stateData!;
}
};

@override
LoadingStyle get loadingStyle =>
LoadingStyle.normal(child: widget.icon ?? Icon(Icons.home));
LoadingStyle.normal(child: widget.icon ?? SizedBox.shrink());

@override
stateUpdated(dynamic data) async {
Expand All @@ -104,8 +101,9 @@ class _BadgeTabState extends NyState<BadgeTab> {

@override
Widget view(BuildContext context) {
bool widgetIsText = widget.icon is Text;
if (currentCount == 0) {
return widget.icon ?? Icon(Icons.home);
return widget.icon ?? SizedBox.shrink();
}
return Badge.count(
count: currentCount,
Expand All @@ -116,9 +114,11 @@ class _BadgeTabState extends NyState<BadgeTab> {
textStyle: widget.textStyle,
padding: widget.padding,
alignment: widget.alignment,
offset: widget.offset,
offset: widgetIsText == true && widget.offset == null
? Offset(20, -10)
: widget.offset,
isLabelVisible: widget.isLabelVisible ?? true,
child: widget.icon ?? Icon(Icons.home),
child: widget.icon,
);
}
}
36 changes: 23 additions & 13 deletions lib/widgets/navigation_hub/navigation_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
label: page.value.title,
activeIcon: BadgeTab.fromNavigationTab(page.value,
index: page.key,
icon: page.value.activeIcon ?? Icon(Icons.home),
icon: page.value.activeIcon,
stateName: "${stateName}_navigation_tab_${page.key}"),
backgroundColor: page.value.backgroundColor,
tooltip: page.value.tooltip,
);
}

return BottomNavigationBarItem(
icon: page.value.icon ?? Icon(Icons.home),
label: page.value.title,
activeIcon: page.value.activeIcon ?? Icon(Icons.home),
icon: page.value.icon ?? Text(page.value.title ?? ""),
label: page.value.icon == null ? "" : page.value.title,
activeIcon: page.value.activeIcon ?? Text(page.value.title ?? ""),
backgroundColor: page.value.backgroundColor,
tooltip: page.value.tooltip,
);
Expand All @@ -139,7 +139,8 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => page.value.page,
builder: (context) =>
page.value.page ?? SizedBox.shrink(),
settings: settings,
),
)
Expand All @@ -148,7 +149,8 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
key: getNavigationKey(pages.entries.elementAt(currentIndex)),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) =>
(pages.entries.elementAt(currentIndex).value.page),
(pages.entries.elementAt(currentIndex).value.page ??
SizedBox.shrink()),
settings: settings,
),
),
Expand Down Expand Up @@ -223,20 +225,26 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
tabs: [
for (MapEntry page in pages.entries)
Tab(
text: layout?.showSelectedLabels == false
text: layout?.showSelectedLabels == false ||
page.value.icon == null
? null
: page.value.title,
icon: page.value.kind == "badge"
? BadgeTab.fromNavigationTab(page.value,
index: page.key,
icon: currentIndex == page.key
? page.value.activeIcon ?? Icon(Icons.home)
: page.value.icon ?? Icon(Icons.home),
? page.value.icon == null
? Text(page.value.title)
: page.value.activeIcon
: page.value.icon ?? Text(page.value.title),
stateName:
"${stateName}_navigation_tab_${page.key}")
: currentIndex == page.key
? page.value.activeIcon ?? Icon(Icons.home)
: page.value.icon ?? Icon(Icons.home),
? page.value.activeIcon
: page.value.icon,
child: page.value.icon == null && page.value.kind != "badge"
? Text(page.value.title)
: null,
)
],
onTap: onTap,
Expand All @@ -248,7 +256,8 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => (page.value.page),
builder: (context) =>
(page.value.page ?? SizedBox.shrink()),
settings: settings,
),
)
Expand All @@ -260,7 +269,8 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
Navigator(
key: getNavigationKey(page),
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => (page.value.page),
builder: (context) =>
(page.value.page ?? SizedBox.shrink()),
settings: settings,
),
)
Expand Down
Loading

0 comments on commit de840ec

Please sign in to comment.