mirror of
https://github.com/Iconica-Development/flutter_shopping.git
synced 2025-05-18 16:33:45 +02:00
fix: gorouter improvements (#4)
This commit is contained in:
parent
bd9d90e175
commit
72e35951b3
7 changed files with 68 additions and 84 deletions
|
@ -15,7 +15,12 @@ final ProductService<MyProduct> productService = ProductService([]);
|
|||
FlutterShoppingConfiguration getFlutterShoppingConfiguration() =>
|
||||
FlutterShoppingConfiguration(
|
||||
// (REQUIRED): Shop builder configuration
|
||||
shopBuilder: (BuildContext context) => ProductPageScreen(
|
||||
shopBuilder: (
|
||||
BuildContext context,
|
||||
String? initialBuildShopId,
|
||||
String? streetName,
|
||||
) =>
|
||||
ProductPageScreen(
|
||||
configuration: ProductPageConfiguration(
|
||||
// (REQUIRED): List of shops that should be displayed
|
||||
// If there is only one, make a list with just one shop.
|
||||
|
@ -71,6 +76,9 @@ FlutterShoppingConfiguration getFlutterShoppingConfiguration() =>
|
|||
),
|
||||
),
|
||||
),
|
||||
|
||||
// (OPTIONAL): Initial build shop id that overrides the initialShop
|
||||
initialBuildShopId: initialBuildShopId,
|
||||
),
|
||||
|
||||
// (REQUIRED): Shopping cart builder configuration
|
||||
|
@ -128,7 +136,7 @@ FlutterShoppingConfiguration getFlutterShoppingConfiguration() =>
|
|||
color: Colors.white,
|
||||
),
|
||||
onPressed: () {
|
||||
context.go(FlutterShoppingRoutes.shop);
|
||||
context.go(FlutterShoppingPathRoutes.shop);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
@ -12,7 +12,7 @@ class Homepage extends StatelessWidget {
|
|||
label: const Text("1"),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.shopping_cart_outlined, size: 50),
|
||||
onPressed: () => context.go(FlutterShoppingRoutes.shop),
|
||||
onPressed: () => context.go(FlutterShoppingPathRoutes.shop),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -63,7 +63,7 @@ OrderDetailConfiguration getDefaultOrderDetailConfiguration(
|
|||
title: const Text("Order Details"),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => context.go(FlutterShoppingRoutes.shoppingCart),
|
||||
onPressed: () => context.go(FlutterShoppingPathRoutes.shoppingCart),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -15,7 +15,11 @@ class FlutterShoppingConfiguration {
|
|||
});
|
||||
|
||||
/// Builder for the shop/product page.
|
||||
final Widget Function(BuildContext context) shopBuilder;
|
||||
final Widget Function(
|
||||
BuildContext context,
|
||||
String? initialBuildShopId,
|
||||
String? streetName,
|
||||
) shopBuilder;
|
||||
|
||||
/// Builder for the shopping cart page.
|
||||
final Widget Function(BuildContext context) shoppingCartBuilder;
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
/// All the routes used in the user-story.
|
||||
mixin FlutterShoppingRoutes {
|
||||
/// All the name routes used in the user-story.
|
||||
mixin FlutterShoppingNameRoutes {
|
||||
/// The shop name route.
|
||||
static const String shop = "shop";
|
||||
|
||||
/// The shopping cart name route.
|
||||
static const String shoppingCart = "shoppingcart";
|
||||
|
||||
/// The order details name route.
|
||||
static const String orderDetails = "orderdetails";
|
||||
|
||||
/// The order success name route.
|
||||
static const String orderSuccess = "ordersuccess";
|
||||
|
||||
/// The order failed name route.
|
||||
static const String orderFailed = "orderfailed";
|
||||
}
|
||||
|
||||
/// All the path routes used in the user-story.
|
||||
mixin FlutterShoppingPathRoutes {
|
||||
/// The shop page route.
|
||||
static const String shop = "/shop";
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter_order_details/flutter_order_details.dart";
|
||||
import "package:flutter_shopping/flutter_shopping.dart";
|
||||
import "package:flutter_shopping/src/config/default_order_detail_configuration.dart";
|
||||
import "package:flutter_shopping/src/go_router.dart";
|
||||
import "package:flutter_shopping/src/widgets/default_order_failed_widget.dart";
|
||||
import "package:flutter_shopping/src/widgets/default_order_succes_widget.dart";
|
||||
import "package:go_router/go_router.dart";
|
||||
|
@ -13,85 +11,41 @@ List<GoRoute> getShoppingStoryRoutes({
|
|||
}) =>
|
||||
<GoRoute>[
|
||||
GoRoute(
|
||||
name: "shop",
|
||||
path: FlutterShoppingRoutes.shop,
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: configuration.shopBuilder(context),
|
||||
name: FlutterShoppingNameRoutes.shop,
|
||||
path: FlutterShoppingPathRoutes.shop,
|
||||
builder: (context, state) => configuration.shopBuilder(
|
||||
context,
|
||||
state.uri.queryParameters["id"],
|
||||
state.uri.queryParameters["street"],
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
name: "shoppingCart",
|
||||
path: FlutterShoppingRoutes.shoppingCart,
|
||||
pageBuilder: (BuildContext context, GoRouterState state) =>
|
||||
buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: configuration.shoppingCartBuilder(context),
|
||||
),
|
||||
name: FlutterShoppingNameRoutes.shoppingCart,
|
||||
path: FlutterShoppingPathRoutes.shoppingCart,
|
||||
builder: (context, state) => configuration.shoppingCartBuilder(context),
|
||||
),
|
||||
GoRoute(
|
||||
name: "orderDetails",
|
||||
path: FlutterShoppingRoutes.orderDetails,
|
||||
pageBuilder: (BuildContext context, GoRouterState state) {
|
||||
if (configuration.orderDetailsBuilder != null) {
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: configuration.orderDetailsBuilder!(context),
|
||||
);
|
||||
}
|
||||
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: OrderDetailScreen(
|
||||
configuration:
|
||||
getDefaultOrderDetailConfiguration(context, configuration),
|
||||
),
|
||||
);
|
||||
},
|
||||
name: FlutterShoppingNameRoutes.orderDetails,
|
||||
path: FlutterShoppingPathRoutes.orderDetails,
|
||||
builder: (context, state) => configuration.orderDetailsBuilder != null
|
||||
? configuration.orderDetailsBuilder!(context)
|
||||
: OrderDetailScreen(
|
||||
configuration:
|
||||
getDefaultOrderDetailConfiguration(context, configuration),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
name: "orderSuccess",
|
||||
path: FlutterShoppingRoutes.orderSuccess,
|
||||
pageBuilder: (BuildContext context, GoRouterState state) {
|
||||
if (configuration.orderSuccessBuilder != null) {
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: configuration.orderSuccessBuilder!(context),
|
||||
);
|
||||
}
|
||||
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: DefaultOrderSucces(configuration: configuration),
|
||||
);
|
||||
},
|
||||
name: FlutterShoppingNameRoutes.orderSuccess,
|
||||
path: FlutterShoppingPathRoutes.orderSuccess,
|
||||
builder: (context, state) => configuration.orderSuccessBuilder != null
|
||||
? configuration.orderSuccessBuilder!(context)
|
||||
: DefaultOrderSucces(configuration: configuration),
|
||||
),
|
||||
GoRoute(
|
||||
name: "orderFailed",
|
||||
path: FlutterShoppingRoutes.orderFailed,
|
||||
pageBuilder: (BuildContext context, GoRouterState state) {
|
||||
if (configuration.orderFailedBuilder != null) {
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: configuration.orderFailedBuilder!(context),
|
||||
);
|
||||
}
|
||||
|
||||
return buildScreenWithFadeTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: DefaultOrderFailed(
|
||||
configuration: configuration,
|
||||
),
|
||||
);
|
||||
},
|
||||
name: FlutterShoppingNameRoutes.orderFailed,
|
||||
path: FlutterShoppingPathRoutes.orderFailed,
|
||||
builder: (context, state) => configuration.orderFailedBuilder != null
|
||||
? configuration.orderFailedBuilder!(context)
|
||||
: DefaultOrderFailed(configuration: configuration),
|
||||
),
|
||||
];
|
||||
|
|
|
@ -26,9 +26,9 @@ Future<void> onCompleteOrderDetails(
|
|||
}
|
||||
|
||||
if (succesful) {
|
||||
go(FlutterShoppingRoutes.orderSuccess);
|
||||
go(FlutterShoppingPathRoutes.orderSuccess);
|
||||
} else {
|
||||
go(FlutterShoppingRoutes.orderFailed);
|
||||
go(FlutterShoppingPathRoutes.orderFailed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ Future<void> onCompleteOrderDetails(
|
|||
void onCompleteShoppingCart(
|
||||
BuildContext context,
|
||||
) {
|
||||
context.go(FlutterShoppingRoutes.orderDetails);
|
||||
context.go(FlutterShoppingPathRoutes.orderDetails);
|
||||
}
|
||||
|
||||
/// Default on complete product page function.
|
||||
|
@ -49,5 +49,5 @@ void onCompleteShoppingCart(
|
|||
void onCompleteProductPage(
|
||||
BuildContext context,
|
||||
) {
|
||||
context.go(FlutterShoppingRoutes.shoppingCart);
|
||||
context.go(FlutterShoppingPathRoutes.shoppingCart);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue