Skip to content

Commit

Permalink
Merge pull request #301 from woltapp/remove-provider-dependency-from-…
Browse files Browse the repository at this point in the history
…coffee-maker-nav2-example

Remove Provider state management dependency from coffee maker nav2 example
  • Loading branch information
ulusoyca authored Aug 17, 2024
2 parents 2c6c245 + 65a11a2 commit fed3802
Show file tree
Hide file tree
Showing 70 changed files with 758 additions and 740 deletions.
33 changes: 0 additions & 33 deletions coffee_maker_navigator_2/lib/app.dart

This file was deleted.

26 changes: 26 additions & 0 deletions coffee_maker_navigator_2/lib/app/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:wolt_di/wolt_di.dart';
import 'package:coffee_maker_navigator_2/app/di/coffee_maker_app_level_dependency_container.dart';
import 'package:demo_ui_components/demo_ui_components.dart';
import 'package:flutter/material.dart';

class CoffeeMakerApp extends StatelessWidget {
const CoffeeMakerApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return DependencyInjector(
child: Builder(builder: (context) {
final appLevelDependencyContainer = DependencyInjector.container<
CoffeeMakerAppLevelDependencyContainer>(context);

return MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: AppThemeData.themeData(context),
routerDelegate: appLevelDependencyContainer.appRouterDelegate,
backButtonDispatcher:
appLevelDependencyContainer.backButtonDispatcher,
);
}),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:coffee_maker_navigator_2/data/auth/local/auth_local_data_source.dart';
import 'package:coffee_maker_navigator_2/app/auth/data/local/auth_local_data_source.dart';

class AuthRepository {
final AuthLocalDataSource localAuthDataSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:coffee_maker_navigator_2/data/auth/repository/auth_repository.dart';
import 'package:coffee_maker_navigator_2/app/auth/data/repository/auth_repository.dart';
import 'package:flutter/foundation.dart';

abstract interface class AuthService {
Expand All @@ -11,6 +11,8 @@ abstract interface class AuthService {
Future<void> logOut();

Future<void> logIn(String email, String password);

void dispose();
}

class AuthServiceImpl implements AuthService {
Expand Down Expand Up @@ -50,4 +52,9 @@ class AuthServiceImpl implements AuthService {
_authStateNotifier.value = false;
}
}

@override
void dispose() {
_authStateNotifier.dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:coffee_maker_navigator_2/data/auth/local/auth_local_data_source.dart';
import 'package:coffee_maker_navigator_2/data/auth/repository/auth_repository.dart';
import 'package:coffee_maker_navigator_2/data/onboarding/local/onboarding_local_data_source.dart';
import 'package:coffee_maker_navigator_2/data/onboarding/repository/onboarding_repository.dart';
import 'package:coffee_maker_navigator_2/domain/auth/auth_service.dart';
import 'package:coffee_maker_navigator_2/domain/onboarding/onboarding_service.dart';
import 'package:coffee_maker_navigator_2/ui/router/view/app_router_delegate.dart';
import 'package:coffee_maker_navigator_2/ui/router/view_model/router_view_model.dart';
import 'package:coffee_maker_navigator_2/app/auth/data/local/auth_local_data_source.dart';
import 'package:coffee_maker_navigator_2/app/auth/data/repository/auth_repository.dart';
import 'package:coffee_maker_navigator_2/app/auth/domain/auth_service.dart';
import 'package:coffee_maker_navigator_2/features/onboarding/data/local/onboarding_local_data_source.dart';
import 'package:coffee_maker_navigator_2/features/onboarding/data/repository/onboarding_repository.dart';
import 'package:coffee_maker_navigator_2/features/onboarding/domain/onboarding_service.dart';
import 'package:coffee_maker_navigator_2/app/router/view/app_router_delegate.dart';
import 'package:coffee_maker_navigator_2/app/router/view_model/router_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -78,6 +78,6 @@ class CoffeeMakerAppLevelDependencyContainer
onboardingService: _onboardingService,
isUserLoggedIn: _authService.authStateListenable.value ?? false,
isTutorialShown: _onboardingService.isTutorialShown(),
)..onInit();
);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'package:coffee_maker_navigator_2/domain/orders/entities/coffee_maker_step.dart';
import 'package:coffee_maker_navigator_2/ui/add_water/view/add_water_screen.dart';
import 'package:coffee_maker_navigator_2/ui/auth/view/auth_screen.dart';
import 'package:coffee_maker_navigator_2/ui/onboarding/view/onboarding_modal_sheet_page.dart';
import 'package:coffee_maker_navigator_2/ui/orders/view/modal_pages/grind/grind_or_reject_modal_page.dart';
import 'package:coffee_maker_navigator_2/ui/orders/view/modal_pages/grind/reject_order_modal_page.dart';
import 'package:coffee_maker_navigator_2/ui/orders/view/orders_screen.dart';
import 'package:coffee_maker_navigator_2/ui/router/entities/app_route_settings_name.dart';
import 'package:coffee_maker_navigator_2/ui/router/view_model/router_view_model.dart';
import 'package:coffee_maker_navigator_2/ui/tutorials/view/single_tutorial_screen.dart';
import 'package:coffee_maker_navigator_2/ui/tutorials/view/tutorials_screen.dart';
import 'package:coffee_maker_navigator_2/features/add_water/ui/view/add_water_screen.dart';
import 'package:coffee_maker_navigator_2/features/orders/domain/entities/coffee_maker_step.dart';
import 'package:coffee_maker_navigator_2/features/tutorial/view/single_tutorial_screen.dart';
import 'package:coffee_maker_navigator_2/features/tutorial/view/tutorials_screen.dart';
import 'package:coffee_maker_navigator_2/features/login/ui/view/login_screen.dart';
import 'package:coffee_maker_navigator_2/features/onboarding/ui/view/onboarding_modal_sheet_page.dart';
import 'package:coffee_maker_navigator_2/features/orders/ui/view/modal_pages/grind/grind_or_reject_modal_page.dart';
import 'package:coffee_maker_navigator_2/features/orders/ui/view/modal_pages/grind/reject_order_modal_page.dart';
import 'package:coffee_maker_navigator_2/features/orders/ui/view/orders_screen.dart';
import 'package:coffee_maker_navigator_2/app/router/entities/app_route_settings_name.dart';
import 'package:coffee_maker_navigator_2/utils/extensions/context_extensions.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

sealed class AppRoutePage<T> extends Page<T> {
Expand All @@ -26,7 +25,7 @@ class AuthRoutePage extends AppRoutePage<void> {
@override
Route<void> createRoute(BuildContext context) {
return MaterialPageRoute<void>(
builder: (context) => const AuthScreen(),
builder: (context) => const LoginScreen(),
settings: this,
);
}
Expand Down Expand Up @@ -115,9 +114,9 @@ class OnboardingModalRoutePage extends AppRoutePage<void> {
(context) => [OnboardingModalSheetPage()],
),
onModalDismissedWithDrag:
context.read<RouterViewModel>().onCloseOnboardingModalSheet,
context.routerViewModel.onCloseOnboardingModalSheet,
onModalDismissedWithBarrierTap:
context.read<RouterViewModel>().onCloseOnboardingModalSheet,
context.routerViewModel.onCloseOnboardingModalSheet,
);
}
}
Expand All @@ -127,8 +126,7 @@ class GrindCoffeeModalRoutePage extends AppRoutePage<void> {
String get name => RouteSettingsName.onboarding.routeName;

final String coffeeOrderId;
final void Function(String orderId, [CoffeeMakerStep? newStep])
onCoffeeOrderStatusChange;
final OnCoffeeOrderStatusChange onCoffeeOrderStatusChange;

GrindCoffeeModalRoutePage(
this.coffeeOrderId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import 'dart:async';

import 'package:coffee_maker_navigator_2/ui/orders/view/widgets/coffee_order_list_view_for_step.dart';
import 'package:coffee_maker_navigator_2/ui/router/entities/app_route_page.dart';
import 'package:coffee_maker_navigator_2/ui/router/view_model/router_view_model.dart';
import 'package:coffee_maker_navigator_2/features/orders/ui/view/widgets/coffee_order_list_view_for_step.dart';
import 'package:coffee_maker_navigator_2/app/router/entities/app_route_page.dart';
import 'package:coffee_maker_navigator_2/utils/extensions/context_extensions.dart';
import 'package:demo_ui_components/demo_ui_components.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

@override
Widget build(BuildContext context) {
final routerViewModel = context.watch<RouterViewModel>();
final pages = routerViewModel.state.pages;

return Navigator(
key: navigatorKey,
pages: pages,
onPopPage: (route, result) {
final context = navigatorKey.currentContext;
final name = route.settings.name;

if (context != null && name != null) {
context
.read<RouterViewModel>()
.onPagePoppedImperatively(poppingPageName: name);
}

return route.didPop(result);
return ValueListenableBuilder<List<AppRoutePage>>(
valueListenable: context.routerViewModel.pages,
builder: (context, pages, __) {
return Navigator(
key: navigatorKey,
pages: pages,
onPopPage: (route, result) {
final context = navigatorKey.currentContext;
final name = route.settings.name;

if (context != null && name != null) {
context.routerViewModel
.onPagePoppedImperatively(poppingPageName: name);
}

return route.didPop(result);
},
observers: [_AppRouteObserver(Theme.of(context).colorScheme)],
);
},
observers: [_AppRouteObserver(Theme.of(context).colorScheme)],
);
}

Expand All @@ -43,8 +43,7 @@ class AppRouterDelegate extends RouterDelegate<Object> with ChangeNotifier {
if (_isImperativePopFromOrderScreenModals(currentContext)) {
return Future.value(true);
}
return currentContext
.read<RouterViewModel>()
return currentContext.routerViewModel
.onPagePoppedWithOperatingSystemIntent();
}

Expand Down
Loading

0 comments on commit fed3802

Please sign in to comment.