Skip to content

Instantly share code, notes, and snippets.

@obadajasm
Created April 16, 2021 13:11
Show Gist options
  • Save obadajasm/e55b6f040d78c186f47550f5bdaa86b6 to your computer and use it in GitHub Desktop.
Save obadajasm/e55b6f040d78c186f47550f5bdaa86b6 to your computer and use it in GitHub Desktop.
a
import 'package:flutter/material.dart';
import 'package:qlevar_router/qlevar_router.dart';
import 'app_routes.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routeInformationParser: QRouteInformationParser(),
routerDelegate: QRouterDelegate(
AppRoutes().routes,
initPath: AppRoutes.productsPage,
),
);
}
}
class ProductsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: [
const SizedBox(height: 30),
Text('ProductsPage'),
const SizedBox(height: 30),
Wrap(
children: List.generate(10, (index) => index.toString())
.map(
(e) => TextButton(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text(e),
),
onPressed: () => QR
.toName(AppRoutes.singleProductPage, params: {'id': e}),
),
)
.toList(),
)
],
),
);
}
}
class SingleProductPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Text('SingleProductPage with id = ${QR.params['id']}'));
}
}
class AppRoutes {
static String productsPage = 'ProductsPage';
static String singleProductPage = 'SingleProductPage';
final routes = [
QRoute(
name: productsPage,
path: '/products',
builder: () => ProductsPage(),
children: [
QRoute(
name: singleProductPage,
path: '/:id',
builder: () => SingleProductPage(),
),
],
),
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment