Skip to content

Commit

Permalink
feat: use native navigation instead of getX navigation (#6)
Browse files Browse the repository at this point in the history
This removes get (getX) as the underlying navigation engine.
Since GetX also routes with the native navigation stack,
this can be directly used instead of passed to get which
then in turn passes it to flutter. While doing this, the services
were redesigned and all navigation related matters are now in
the navigation service only.

BREAKING CHANGE: The `DialogService` was deleted.
Dialog related methods are now in the `NavigationService`.

BREAKING CHANGE: The `BottomSheetService` was deleted.
All related methods are now in the `NavigationService`.

BREAKING CHANGE: the close methods for dialog and
sheet (`closeDialog` and `closeSheet`) are removed. They
are unified in the method `closeOverlay` in the `NavigationService`.

BREAKING CHANGE: Since getX is removed, the base logic of
the entry point in the app could be simplified. Instead of
the key and observer being methods, they are now static
initialized fields on the navigation service.

BRAKING CHANGE: The `preventDuplicates` parameter for the
navigation method is gone. Currently, with native
navigation, the user of the package is responsible to
have an overview of the navigation stack.
  • Loading branch information
buehler authored May 7, 2024
1 parent a966fae commit e9cf309
Show file tree
Hide file tree
Showing 26 changed files with 816 additions and 1,123 deletions.
12 changes: 6 additions & 6 deletions packages/fluorflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget {
initialRoute: AppRoute.homeView.path,
onGenerateRoute: onGenerateRoute,
navigatorKey: NavigationService.navigatorKey,
navigatorObservers: [NavigationService.observer()],
navigatorObservers: [NavigationService.observer],
);
}
}
Expand All @@ -41,12 +41,12 @@ Especially the part for routing is important (if you use FluorFlow views and rou
initialRoute: AppRoute.homeView.path,
onGenerateRoute: onGenerateRoute,
navigatorKey: NavigationService.navigatorKey,
navigatorObservers: [NavigationService.observer()],
navigatorObservers: [NavigationService.observer],
```

This enables the routing system of FluorFlow (which uses GetX underneath).
This enables the routing system of FluorFlow.

The other parts of the material app can be as you wish.
The other parts of the app can be as you wish.

## Views

Expand Down Expand Up @@ -176,12 +176,12 @@ final class GreetingBottomSheet extends FluorFlowSimpleBottomSheet<void> {
}
```

Bottom sheets are shown via the `BottomSheetService` that has extension methods
Bottom sheets are shown via the `NavigationService` that has extension methods
attached for each bottom sheet. Parameters of sheets are taken into account
when used with the fluorflow generator.

Dialogs work exactly the same way as bottom sheets, but are shown via the
`DialogService` and have another base class.
`Dialogs` extension in the `NavigationService` and have another base class.

**Important:** Bottom sheets are always wrapped in a `Scaffold` widget. Thus,
they inherit your styles. `Dialogs` do not have this behavior (by design).
Expand Down
2 changes: 1 addition & 1 deletion packages/fluorflow/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class MyApp extends StatelessWidget {
initialRoute: AppRoute.homeView.path,
onGenerateRoute: onGenerateRoute,
navigatorKey: NavigationService.navigatorKey,
navigatorObservers: [NavigationService.observer()],
navigatorObservers: [NavigationService.observer],
);
}
4 changes: 4 additions & 0 deletions packages/fluorflow/example/lib/views/detail/detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ final class DetailView extends FluorFlowView<DetailViewModel> {
onPressed: viewModel.back,
child: const Text('Back'),
),
ElevatedButton(
onPressed: viewModel.rootBack,
child: const Text('Root to home view'),
),
ElevatedButton(
onPressed: viewModel.showBottomSheet,
child: const Text('Show Bottom Sheet'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'dart:async';

import 'package:example/app.bottom_sheets.dart';
import 'package:fluorflow/fluorflow.dart';

import '../../app.router.dart';

final class DetailViewModel extends DataViewModel<int> {
final _navService = locator<NavigationService>();
final _sheets = locator<BottomSheetService>();

DetailViewModel() : super(0);

void showBottomSheet() =>
_sheets.showGreetingBottomSheet(callback: () {}, onElement: (_) {});
_navService.showGreetingBottomSheet(callback: () {}, onElement: (_) {});

void back() => _navService.back();

void rootBack() => _navService.rootToHomeView();

void addOne() => data += 1;
}
5 changes: 2 additions & 3 deletions packages/fluorflow/example/lib/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import '../../app.dialogs.dart';
import '../../app.router.dart';

final class HomeViewModel extends BaseViewModel {
final _dialogService = locator<DialogService>();
final _navService = locator<NavigationService>();

var _counter = 0;
Expand All @@ -16,9 +15,9 @@ final class HomeViewModel extends BaseViewModel {
notifyListeners();
}

void showTestDialog() => _dialogService.showRedDialog(elements: []);
void showTestDialog() => _navService.showRedDialog(elements: []);

void showSmallDialog() => _dialogService.showSmallDialog();
void showSmallDialog() => _navService.showSmallDialog();

void goToDetail() => _navService.navigateToDetailView();
}
2 changes: 0 additions & 2 deletions packages/fluorflow/lib/fluorflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
library fluorflow;

export 'src/bottom_sheets/bottom_sheet.dart';
export 'src/bottom_sheets/bottom_sheet_service.dart';
export 'src/bottom_sheets/simple_bottom_sheet.dart';
export 'src/dialogs/dialog.dart';
export 'src/dialogs/dialog_service.dart';
export 'src/dialogs/simple_dialog.dart';
export 'src/locator/locator.dart';
export 'src/navigation/navigation_service.dart';
Expand Down
10 changes: 7 additions & 3 deletions packages/fluorflow/lib/src/annotations/bottom_sheet_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ class BottomSheetConfig {
/// If set to false, the bottom sheet will be displayed at the bottom third(-ish) of the screen.
final bool defaultFullscreen;

/// Whether the bottom sheet should ignore the safe area and take up the entire screen.
/// Whether the bottom sheet should ignore or use the safe area and take up the entire screen.
/// This is most likely used in combination with [defaultFullscreen].
final bool defaultIgnoreSafeArea;
final bool defaultUseSafeArea;

/// Whether the bottom sheet can be dragged by the user.
final bool defaultDraggable;

/// Whether the bottom sheet should show a drag handle.
final bool defaultShowDragHandle;

/// Decorate a bottom sheet or simple bottomsheet with a [BottomSheetConfig].
const BottomSheetConfig({
this.defaultBarrierColor = 0x80000000,
this.defaultFullscreen = false,
this.defaultIgnoreSafeArea = true,
this.defaultUseSafeArea = false,
this.defaultDraggable = true,
this.defaultShowDragHandle = false,
});
}
43 changes: 0 additions & 43 deletions packages/fluorflow/lib/src/bottom_sheets/bottom_sheet_service.dart

This file was deleted.

39 changes: 0 additions & 39 deletions packages/fluorflow/lib/src/dialogs/dialog_service.dart

This file was deleted.

Loading

0 comments on commit e9cf309

Please sign in to comment.