Skip to content

Commit 2f10023

Browse files
committed
v6.26.0
1 parent 636deb8 commit 2f10023

File tree

11 files changed

+810
-4
lines changed

11 files changed

+810
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [6.26.0] - 2025-04-16
2+
3+
* Added: `JourneyState` class to help manage `NavigationHubLayout.journey`
4+
* Added: `JourneyHelper` class to help manage JourneyState's
5+
* Added: `makeJourneyWidget` method to `MetroService` class
6+
* Added: `parentOption` to constants
7+
* Added: `syncToStorage` method to NySession class. This will sync the session data to storage
8+
* Added: `syncFromStorage` method to NySession class. This will sync the session data from storage
9+
110
## [6.25.1] - 2025-04-09
211

312
* Fix `NyStorage.read` method

lib/helpers/ny_session.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '/local_storage/local_storage.dart';
12
import 'backpack.dart';
23

34
/// Create a new session
@@ -52,4 +53,24 @@ class NySession {
5253
}
5354
return sessionData;
5455
}
56+
57+
/// Sync to Storage
58+
Future syncToStorage() async {
59+
Map<String, dynamic>? sessionData = data();
60+
if (sessionData == null) {
61+
return;
62+
}
63+
await NyStorage.saveJson("${name}_session", sessionData);
64+
}
65+
66+
/// Sync from Storage
67+
Future syncFromStorage() async {
68+
final sessionData = await NyStorage.readJson("${name}_session");
69+
if (sessionData == null) {
70+
return;
71+
}
72+
for (MapEntry key in sessionData.entries) {
73+
add(key.key, key.value);
74+
}
75+
}
5576
}

lib/metro/constants/strings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const String bottomNavFlag = 'bottom-nav';
1414
// options
1515
const String postmanCollectionOption = 'postman';
1616
const String commandCategoryOption = 'category';
17+
const String parentOption = 'parent';
1718

1819
// folders
1920
const String yamlPath = 'pubspec.yaml';

lib/metro/metro_service.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,31 @@ final Map<Type, dynamic> modelDecoders = {${reg.allMatches(file).map((e) => e.gr
556556
});
557557
}
558558

559+
/// Creates a new Journey Widget.
560+
static makeJourneyWidget(String className, String value,
561+
{String folderPath = widgetsFolder,
562+
bool forceCreate = false,
563+
String? creationPath}) async {
564+
String name = className.replaceAll(RegExp(r'(_?widget)'), "");
565+
566+
// create missing directories in the project
567+
await _makeDirectory(folderPath);
568+
await createDirectoriesFromCreationPath(creationPath, folderPath);
569+
570+
// create file path
571+
String filePath = createPathForDartFile(
572+
folderPath: folderPath,
573+
className: name,
574+
prefix: 'widget',
575+
creationPath: creationPath);
576+
577+
await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
578+
await _createNewFile(filePath, value, onSuccess: () {
579+
MetroConsole.writeInGreen(
580+
'[Journey Widget] ${name.snakeCase} created 🎉');
581+
});
582+
}
583+
559584
/// Creates a new State Managed Widget.
560585
static makeStateManagedWidget(String className, String value,
561586
{String folderPath = widgetsFolder,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import '/helpers/backpack.dart';
2+
import '/widgets/navigation_hub/navigation_hub.dart';
3+
4+
/// A helper class for journey navigation
5+
class JourneyHelper {
6+
final String navigationHubState;
7+
8+
/// Create a new journey helper for the given navigation hub state
9+
JourneyHelper(this.navigationHubState);
10+
11+
/// Get the current step index (0-based)
12+
int getCurrentStep() {
13+
final currentData =
14+
Backpack.instance.read('${navigationHubState}_current_tab');
15+
return (currentData is int) ? currentData : 0;
16+
}
17+
18+
/// Get the total number of steps
19+
int getTotalSteps() {
20+
final totalPagesData =
21+
Backpack.instance.read('${navigationHubState}_total_pages');
22+
return (totalPagesData is int) ? totalPagesData : 0;
23+
}
24+
25+
/// Check if this is the first step
26+
bool isFirstStep() {
27+
return getCurrentStep() == 0;
28+
}
29+
30+
/// Check if this is the last step
31+
bool isLastStep() {
32+
final currentStep = getCurrentStep();
33+
final totalSteps = getTotalSteps();
34+
return currentStep >= totalSteps - 1;
35+
}
36+
37+
/// Get the completion percentage (0.0 to 1.0)
38+
double getCompletionPercentage() {
39+
final currentStep = getCurrentStep();
40+
final totalSteps = getTotalSteps();
41+
42+
if (totalSteps == 0) return 0.0;
43+
return (currentStep + 1) / totalSteps;
44+
}
45+
46+
/// Navigate to the next step, returns false if already at the last step
47+
Future<bool> nextStep() async {
48+
final actions = NavigationHubStateActions(navigationHubState);
49+
return await actions.nextPage();
50+
}
51+
52+
/// Navigate to the previous step, returns false if already at the first step
53+
Future<bool> previousStep() async {
54+
final actions = NavigationHubStateActions(navigationHubState);
55+
return await actions.previousPage();
56+
}
57+
58+
/// Jump to a specific step by index
59+
void goToStep(int stepIndex) {
60+
final actions = NavigationHubStateActions(navigationHubState);
61+
actions.currentTabIndex(stepIndex);
62+
}
63+
64+
/// Reset the current step
65+
void resetCurrentStep() {
66+
final actions = NavigationHubStateActions(navigationHubState);
67+
actions.resetTabIndex(getCurrentStep());
68+
}
69+
}

0 commit comments

Comments
 (0)