Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bottomSheet page type #155

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions example/lib/pages/welcome/bottom_sheet_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';

class BottomSheetPage extends StatelessWidget {
const BottomSheetPage({super.key});

@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text('BottomSheetPage Content'),
),
);
}
}
78 changes: 42 additions & 36 deletions example/lib/pages/welcome/welcome_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,48 @@ class WelcomeView extends StatelessWidget {
title: const Text('Welcome to Qlevar Router'),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
NodeWidget(
name: 'Store',
// Navigate with route name
onPressed: () => QR.toName(StoreRoutes.store),
),
NodeWidget(
name: 'Dashboard',
onPressed: () => QR.toName(DashboardRoutes.dashboard),
),
NodeWidget(
name: 'Mobile',
onPressed: () => QR.toName(MobileRoutes.mobile),
),
NodeWidget(
name: 'Middleware',
// Navigate with route path
onPressed: () => QR.to('/parent'),
),
NodeWidget(
name: 'Await routes results',
onPressed: () => QR.to('/await-result'),
),
NodeWidget(
name: 'Declarative',
onPressed: () => QR.to('/declarative'),
),
NodeWidget(
name: 'Editable Routes',
onPressed: () => QR.to('/editable-routes'),
),
const SingleNavigatorRouterExample(),
],
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
NodeWidget(
name: 'Store',
// Navigate with route name
onPressed: () => QR.toName(StoreRoutes.store),
),
NodeWidget(
name: 'Dashboard',
onPressed: () => QR.toName(DashboardRoutes.dashboard),
),
NodeWidget(
name: 'Mobile',
onPressed: () => QR.toName(MobileRoutes.mobile),
),
NodeWidget(
name: 'Middleware',
// Navigate with route path
onPressed: () => QR.to('/parent'),
),
NodeWidget(
name: 'Await routes results',
onPressed: () => QR.to('/await-result'),
),
NodeWidget(
name: 'Declarative',
onPressed: () => QR.to('/declarative'),
),
NodeWidget(
name: 'Editable Routes',
onPressed: () => QR.to('/editable-routes'),
),
const SingleNavigatorRouterExample(),
NodeWidget(
name: 'BottomSheet Page',
onPressed: () => QR.push('/bottom-sheet'),
),
],
),
),
),
floatingActionButton: const DebugTools(),
Expand Down
12 changes: 12 additions & 0 deletions example/lib/routes/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:qlevar_router/qlevar_router.dart';
import '../pages/declarative/declarative_view.dart';
import '../pages/login/login_view.dart';
import '../pages/not_found/not_found_view.dart';
import '../pages/welcome/bottom_sheet_page.dart';
import '../pages/welcome/welcome_view.dart';
import '../services/auth_service.dart';
import 'await_result_routes.dart';
Expand All @@ -17,6 +18,7 @@ import 'store_routes.dart';
class AppRoutes {
static const String root = 'root';
static const String login = 'login';
static const String bottomSheetPage = 'bottom_sheet_page';

void setup() {
// enable debug logging for all routes
Expand Down Expand Up @@ -97,5 +99,15 @@ class AppRoutes {
path: '/declarative',
declarativeBuilder: (k) => DeclarativePage(k),
),
// Add bottom sheet page route
QRoute(
path: '/bottom-sheet',
name: bottomSheetPage,
pageType: const QModalBottomSheetPage(
showDragHandle: true,
isDismissible: true,
anchorPoint: Offset(100, 200)),
builder: () => const BottomSheetPage(),
),
];
}
22 changes: 22 additions & 0 deletions lib/src/pages/page_creator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ abstract class _PageConverter {
if (pageType is QCustomPage) {
return _getCustomPage(child);
}
if (pageType is QModalBottomSheetPage) {
return _getModalBottomSheetPage(child);
}
return _getMaterialPage(child);
}

Expand Down Expand Up @@ -83,6 +86,25 @@ abstract class _PageConverter {
);
}

QModalBottomSheetPageInternal _getModalBottomSheetPage(Widget child) {
final page = pageType as QModalBottomSheetPage;
return QModalBottomSheetPageInternal(
name: pageName,
child: child,
restorationId: _getRestorationId(),
key: key,
matchKey: matchKey,
isScrollControlled: page.isScrollControlled,
isDismissible: page.isDismissible,
enableDrag: page.enableDrag,
showDragHandle: page.showDragHandle,
useSafeArea: page.useSafeArea,
barrierOnTapHint: page.barrierOnTapHint,
barrierLabel: page.barrierOnTapHint,
anchorPoint: page.anchorPoint,
);
}

Widget _buildTransaction(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) =>
_getTransaction(pageType as QCustomPage, child, animation);
Expand Down
45 changes: 45 additions & 0 deletions lib/src/pages/qpage_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,48 @@ class QCustomPageInternal extends QPageInternal {
);
}
}

class QModalBottomSheetPageInternal extends QPageInternal {
const QModalBottomSheetPageInternal({
required this.child,
required super.matchKey,
this.isDismissible = true,
this.isScrollControlled = false,
this.enableDrag = true,
this.showDragHandle,
this.useSafeArea = false,
this.barrierLabel,
this.barrierOnTapHint,
this.anchorPoint,
super.key,
super.restorationId,
super.name,
super.arguments,
});

final Widget child;
final bool isScrollControlled;
final bool? showDragHandle;
final bool isDismissible;
final bool enableDrag;
final bool useSafeArea;
final String? barrierLabel;
final String? barrierOnTapHint;
final Offset? anchorPoint;

@override
Route createRoute(BuildContext context) {
return ModalBottomSheetRoute(
settings: this,
builder: (_) => child,
isScrollControlled: isScrollControlled,
barrierLabel: barrierLabel,
barrierOnTapHint: barrierOnTapHint,
isDismissible: isDismissible,
showDragHandle: showDragHandle,
enableDrag: enableDrag,
useSafeArea: useSafeArea,
anchorPoint: anchorPoint,
);
}
}
24 changes: 24 additions & 0 deletions lib/src/pages/qpages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ class QFadePage extends QCustomPage {

final Curve? curve;
}

class QModalBottomSheetPage extends QPage {
const QModalBottomSheetPage({
this.isScrollControlled = false,
this.isDismissible = true,
this.barrierDismissible = true,
this.enableDrag = true,
this.useSafeArea = false,
this.showDragHandle,
this.barrierLabel,
this.barrierOnTapHint,
this.anchorPoint,
String? restorationId,
}) : super(false, false, restorationId);
final bool isScrollControlled;
final bool isDismissible;
final bool barrierDismissible;
final bool enableDrag;
final bool useSafeArea;
final bool? showDragHandle;
final String? barrierLabel;
final String? barrierOnTapHint;
final Offset? anchorPoint;
}