Skip to content

Commit 4cdf7cd

Browse files
committed
v6.17.0
1 parent 31985bb commit 4cdf7cd

File tree

6 files changed

+190
-67
lines changed

6 files changed

+190
-67
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## [6.17.0] - 2025-01-26
2+
3+
* Added comprehensive DateTime manipulation methods:
4+
* Year operations: `addYears()` and `subtractYears()`
5+
* Month operations: `addMonths()` and `subtractMonths()`
6+
* Day operations: `addDays()` and `subtractDays()`
7+
* Hour operations: `addHours()` and `subtractHours()`
8+
* Minute operations: `addMinutes()` and `subtractMinutes()`
9+
* Second operations: `addSeconds()` and `subtractSeconds()`
10+
* Update NavigationHub to support the following:
11+
* Set a default current tab index: Override `currentIndex` in your `NavigationHub` class
12+
* New `bottomNavBuilder` method to build the bottom navigation bar
13+
* DateTime extension:
14+
* Allow `toDateString` to accept a `String` format
15+
* Add `toDateStringUK` to format the date in UK format
16+
* Add `toDateStringUS` to format the date in US format
17+
* New `localAsset` method added to `AssetImage`
18+
* Update pubspec.yaml
19+
120
## [6.16.1] - 2025-01-16
221

322
* Small change to `getPublicAsset` to remove first slash if it exists

example/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ packages:
313313
dependency: transitive
314314
description:
315315
name: get_time_ago
316-
sha256: "0f50a87080a720f5491266a3f7c79109f95943decd10b66c84b5aef802f1d959"
316+
sha256: "1a640756920c9332f7252d0be53faa95f2a5f313d88c6ddbfb5c5f2b3bc65458"
317317
url: "https://pub.dev"
318318
source: hosted
319-
version: "2.1.1"
319+
version: "2.1.2"
320320
http:
321321
dependency: transitive
322322
description:
@@ -411,7 +411,7 @@ packages:
411411
path: ".."
412412
relative: true
413413
source: path
414-
version: "6.14.4"
414+
version: "6.17.0"
415415
path:
416416
dependency: transitive
417417
description:

lib/helpers/extensions.dart

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ extension NyBool on bool? {
161161
}
162162
}
163163

164+
/// Extensions for [AssetImage]
165+
extension NyAssetImage on AssetImage {
166+
/// Get the image from public/images
167+
AssetImage localAsset() {
168+
return AssetImage(getImageAsset(assetName));
169+
}
170+
}
171+
164172
/// Extensions for [DateTime]
165173
extension NyDateTime on DateTime? {
166174
/// Get the locale of the device.
@@ -200,16 +208,97 @@ extension NyDateTime on DateTime? {
200208
return this!.hour >= 0 && this!.hour < 6;
201209
}
202210

211+
/// Add years to a [DateTime]
212+
DateTime addYears(int years) {
213+
if (this == null) throw Exception("DateTime is null");
214+
return DateTime(this!.year + years, this!.month, this!.day);
215+
}
216+
217+
/// Subtract years from a [DateTime]
218+
DateTime subtractYears(int years) {
219+
if (this == null) throw Exception("DateTime is null");
220+
return DateTime(this!.year - years, this!.month, this!.day);
221+
}
222+
223+
/// Add months to a [DateTime]
224+
DateTime addMonths(int months) {
225+
if (this == null) throw Exception("DateTime is null");
226+
return DateTime(this!.year, this!.month + months, this!.day);
227+
}
228+
229+
/// Subtract months from a [DateTime]
230+
DateTime subtractMonths(int months) {
231+
if (this == null) throw Exception("DateTime is null");
232+
return DateTime(this!.year, this!.month - months, this!.day);
233+
}
234+
235+
/// Add days to a [DateTime]
236+
DateTime addDays(int days) {
237+
if (this == null) throw Exception("DateTime is null");
238+
return this!.add(Duration(days: days));
239+
}
240+
241+
/// Subtract days from a [DateTime]
242+
DateTime subtractDays(int days) {
243+
if (this == null) throw Exception("DateTime is null");
244+
return this!.subtract(Duration(days: days));
245+
}
246+
247+
/// Add hours to a [DateTime]
248+
DateTime addHours(int hours) {
249+
if (this == null) throw Exception("DateTime is null");
250+
return this!.add(Duration(hours: hours));
251+
}
252+
253+
/// Subtract hours from a [DateTime]
254+
DateTime subtractHours(int hours) {
255+
if (this == null) throw Exception("DateTime is null");
256+
return this!.subtract(Duration(hours: hours));
257+
}
258+
259+
DateTime addMinutes(int minutes) {
260+
if (this == null) throw Exception("DateTime is null");
261+
return this!.add(Duration(minutes: minutes));
262+
}
263+
264+
/// Subtract minutes from a [DateTime]
265+
DateTime subtractMinutes(int minutes) {
266+
if (this == null) throw Exception("DateTime is null");
267+
return this!.subtract(Duration(minutes: minutes));
268+
}
269+
270+
/// Add seconds to a [DateTime]
271+
DateTime addSeconds(int seconds) {
272+
if (this == null) throw Exception("DateTime is null");
273+
return this!.add(Duration(seconds: seconds));
274+
}
275+
276+
/// Subtract seconds from a [DateTime]
277+
DateTime subtractSeconds(int seconds) {
278+
if (this == null) throw Exception("DateTime is null");
279+
return this!.subtract(Duration(seconds: seconds));
280+
}
281+
203282
/// Format [DateTime] to DateTimeString - yyyy-MM-dd HH:mm:ss
204283
String? toDateTimeString() {
205284
if (this == null) return null;
206285
return intl.DateFormat("yyyy-MM-dd HH:mm:ss", _locale).format(this!);
207286
}
208287

209288
/// Format [DateTime] to toDateString - yyyy-MM-dd
210-
String? toDateString() {
289+
String? toDateString({String format = "yyyy-MM-dd"}) {
211290
if (this == null) return null;
212-
return intl.DateFormat("yyyy-MM-dd", _locale).format(this!);
291+
return intl.DateFormat(format, _locale).format(this!);
292+
}
293+
294+
/// Format [DateTime] to toDateString - yyyy-MM-dd
295+
String? toDateStringUK({String format = "dd/MM/yyyy"}) {
296+
return toDateString(format: format);
297+
}
298+
299+
/// Format [DateTime] to toDateString - yyyy-MM-dd
300+
String? toDateStringUS({String format = "MM/dd/yyyy"}) {
301+
return toDateString(format: format);
213302
}
214303

215304
/// Format [DateTime] to toTimeString - HH:mm or HH:mm:ss

lib/widgets/navigation_hub/navigation_hub.dart

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
2828
NavigationHubLayout? layout;
2929

3030
/// The current index of the page
31-
int currentIndex = 0;
31+
int? currentIndex;
3232

3333
/// The navigator keys
3434
Map<int, UniqueKey> navigatorKeys = {};
@@ -39,10 +39,13 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
3939
/// The reset map
4040
Map<int, bool> reset = {};
4141

42+
/// Get the current index
43+
int get getCurrentIndex => currentIndex ?? 0;
44+
4245
@override
4346
get init => () {
4447
int? activeTab = data(defaultValue: {"tab-index": 0})['tab-index'];
45-
currentIndex = activeTab ?? 0;
48+
currentIndex ??= activeTab ?? 0;
4649

4750
if (pages is Future Function()) {
4851
awaitData(perform: () async {
@@ -128,73 +131,86 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
128131
);
129132
}
130133

134+
/// Helper to build the bottom nav widget
135+
Widget bottomNavBuilder(
136+
BuildContext context, Widget body, Widget? bottomNavigationBar) {
137+
throw UnimplementedError();
138+
}
139+
131140
@override
132141
Widget view(BuildContext context) {
133142
Map<int, NavigationTab> pages = orderedPages;
134143
if (layout?.kind == "bottomNav") {
135-
return Scaffold(
136-
body: maintainState
137-
? IndexedStack(index: currentIndex, children: [
138-
for (var page in pages.entries)
139-
Navigator(
140-
key: getNavigationKey(page),
141-
onGenerateRoute: (settings) => MaterialPageRoute(
142-
builder: (context) =>
143-
page.value.page ?? SizedBox.shrink(),
144-
settings: settings,
145-
),
146-
)
147-
])
148-
: Navigator(
149-
key: getNavigationKey(pages.entries.elementAt(currentIndex)),
150-
onGenerateRoute: (settings) => MaterialPageRoute(
151-
builder: (context) =>
152-
(pages.entries.elementAt(currentIndex).value.page ??
153-
SizedBox.shrink()),
154-
settings: settings,
155-
),
156-
),
157-
bottomNavigationBar: BottomNavigationBar(
158-
currentIndex: currentIndex,
159-
onTap: onTap,
160-
selectedLabelStyle: layout?.selectedLabelStyle ??
161-
TextStyle(
162-
color: Colors.black,
163-
fontWeight: FontWeight.w600,
144+
Widget body = maintainState
145+
? IndexedStack(index: currentIndex, children: [
146+
for (var page in pages.entries)
147+
Navigator(
148+
key: getNavigationKey(page),
149+
onGenerateRoute: (settings) => MaterialPageRoute(
150+
builder: (context) => page.value.page ?? SizedBox.shrink(),
151+
settings: settings,
152+
),
153+
)
154+
])
155+
: Navigator(
156+
key: getNavigationKey(pages.entries.elementAt(getCurrentIndex)),
157+
onGenerateRoute: (settings) => MaterialPageRoute(
158+
builder: (context) =>
159+
(pages.entries.elementAt(getCurrentIndex).value.page ??
160+
SizedBox.shrink()),
161+
settings: settings,
164162
),
165-
unselectedLabelStyle: layout?.unselectedLabelStyle ??
166-
TextStyle(
167-
color: Colors.black,
168-
fontWeight: FontWeight.w400,
169-
),
170-
showSelectedLabels: layout?.showSelectedLabels ?? true,
171-
showUnselectedLabels: layout?.showUnselectedLabels ?? true,
172-
selectedItemColor: layout?.selectedItemColor ?? Colors.black,
173-
unselectedItemColor: layout?.unselectedItemColor ?? Colors.black,
174-
selectedFontSize: layout?.selectedFontSize ?? 14.0,
175-
unselectedFontSize: layout?.unselectedFontSize ?? 12.0,
176-
iconSize: layout?.iconSize ?? 24.0,
177-
elevation: layout?.elevation ?? 8.0,
178-
backgroundColor: layout?.backgroundColor,
179-
type: layout?.type ?? BottomNavigationBarType.fixed,
180-
items: [
181-
for (MapEntry<int, NavigationTab> page in pages.entries)
182-
_getBottomNavigationBarItem(page),
183-
],
184-
),
163+
);
164+
165+
Widget? bottomNavigationBar = BottomNavigationBar(
166+
currentIndex: getCurrentIndex,
167+
onTap: onTap,
168+
selectedLabelStyle: layout?.selectedLabelStyle ??
169+
TextStyle(
170+
color: Colors.black,
171+
fontWeight: FontWeight.w600,
172+
),
173+
unselectedLabelStyle: layout?.unselectedLabelStyle ??
174+
TextStyle(
175+
color: Colors.black,
176+
fontWeight: FontWeight.w400,
177+
),
178+
showSelectedLabels: layout?.showSelectedLabels ?? true,
179+
showUnselectedLabels: layout?.showUnselectedLabels ?? true,
180+
selectedItemColor: layout?.selectedItemColor ?? Colors.black,
181+
unselectedItemColor: layout?.unselectedItemColor ?? Colors.black,
182+
selectedFontSize: layout?.selectedFontSize ?? 14.0,
183+
unselectedFontSize: layout?.unselectedFontSize ?? 12.0,
184+
iconSize: layout?.iconSize ?? 24.0,
185+
elevation: layout?.elevation ?? 8.0,
186+
backgroundColor: layout?.backgroundColor,
187+
type: layout?.type ?? BottomNavigationBarType.fixed,
188+
items: [
189+
for (MapEntry<int, NavigationTab> page in pages.entries)
190+
_getBottomNavigationBarItem(page),
191+
],
185192
);
193+
try {
194+
return bottomNavBuilder(context, body, bottomNavigationBar);
195+
} on UnimplementedError catch (_) {
196+
return Scaffold(
197+
body: body,
198+
bottomNavigationBar: bottomNavigationBar,
199+
);
200+
}
186201
}
202+
187203
if (layout?.kind == "topNav") {
188204
return DefaultTabController(
189205
length: pages.length,
190-
initialIndex: currentIndex,
206+
initialIndex: getCurrentIndex,
191207
animationDuration: layout?.animationDuration,
192208
child: Scaffold(
193209
appBar: AppBar(
194210
backgroundColor: layout?.backgroundColor,
195-
title: pages[currentIndex]?.title == null
211+
title: pages[getCurrentIndex]?.title == null
196212
? null
197-
: Text(pages[currentIndex]?.title ?? ""),
213+
: Text(pages[getCurrentIndex]?.title ?? ""),
198214
toolbarHeight: (layout?.hideAppBarTitle ?? true) ? 0 : null,
199215
bottom: TabBar(
200216
isScrollable: layout?.isScrollable ?? false,
@@ -232,14 +248,14 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
232248
icon: page.value.kind == "badge"
233249
? BadgeTab.fromNavigationTab(page.value,
234250
index: page.key,
235-
icon: currentIndex == page.key
251+
icon: getCurrentIndex == page.key
236252
? page.value.icon == null
237253
? Text(page.value.title)
238254
: page.value.activeIcon
239255
: page.value.icon ?? Text(page.value.title),
240256
stateName:
241257
"${stateName}_navigation_tab_${page.key}")
242-
: currentIndex == page.key
258+
: getCurrentIndex == page.key
243259
? page.value.activeIcon
244260
: page.value.icon,
245261
child: page.value.icon == null && page.value.kind != "badge"
@@ -251,7 +267,7 @@ abstract class NavigationHub<T extends StatefulWidget> extends NyState<T> {
251267
),
252268
),
253269
body: maintainState
254-
? IndexedStack(index: currentIndex, children: [
270+
? IndexedStack(index: getCurrentIndex, children: [
255271
for (var page in pages.entries)
256272
Navigator(
257273
key: getNavigationKey(page),

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ packages:
321321
dependency: "direct main"
322322
description:
323323
name: get_time_ago
324-
sha256: "0f50a87080a720f5491266a3f7c79109f95943decd10b66c84b5aef802f1d959"
324+
sha256: "1a640756920c9332f7252d0be53faa95f2a5f313d88c6ddbfb5c5f2b3bc65458"
325325
url: "https://pub.dev"
326326
source: hosted
327-
version: "2.1.1"
327+
version: "2.1.2"
328328
http:
329329
dependency: transitive
330330
description:

pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: nylo_support
22
description: Support library for the Nylo framework. This library supports routing, widgets, localization, cli, storage and more.
3-
version: 6.16.1
3+
version: 6.17.0
44
homepage: https://nylo.dev
55
repository: https://github.com/nylo-core/support/tree/6.x
66
issue_tracker: https://github.com/nylo-core/support/issues
@@ -23,7 +23,7 @@ dependencies:
2323
flutter_staggered_grid_view: ^0.7.0
2424
dio: ^5.7.0
2525
recase: ^4.1.0
26-
get_time_ago: ^2.1.1
26+
get_time_ago: ^2.1.2
2727
flutter_styled_toast: ^2.2.1
2828
animate_do: ^3.3.4
2929
pull_to_refresh_flutter3: ^2.0.2
@@ -60,5 +60,4 @@ screenshots:
6060

6161
# The following section is specific to Flutter.
6262
flutter:
63-
6463
uses-material-design: true

0 commit comments

Comments
 (0)