Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
156 changes: 125 additions & 31 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ class HomePage extends ConsumerStatefulWidget {
}

class _HomePageState extends ConsumerState<HomePage> {
bool swipeable = false;
final Map<int, Map<String, Widget>> _routes = const {
0: {
'/': HomeFeeds(),
FeedDetail.route: FeedDetail(),
},
1: {
'/': ProductList(),
'/': ProductPage(),
ProductDetail.route: ProductDetail(),
ProductComments.route: ProductComments(),
},
Expand Down Expand Up @@ -193,7 +194,7 @@ class _HomePageState extends ConsumerState<HomePage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SizedBox(
width: 100,
width: 50,
),
FloatingActionButton.extended(
heroTag: 'showSnackBar',
Expand Down Expand Up @@ -223,6 +224,16 @@ class _HomePageState extends ConsumerState<HomePage> {
setState(() {});
},
),
FloatingActionButton(
heroTag: 'swipe',
child: Icon(
swipeable ? Icons.swipe : Icons.touch_app_outlined),
onPressed: () {
// Programmatically toggle the Navbar visibility
swipeable = !swipeable;
setState(() {});
},
),
FloatingActionButton(
heroTag: 'darkmode',
child: Icon(appSetting.isDarkMode
Expand All @@ -241,6 +252,14 @@ class _HomePageState extends ConsumerState<HomePage> {
}),
body: Builder(builder: (context) {
return NavbarRouter(
swipeable: swipeable,
// swipeableLeftArea: Rect.fromLTWH(
// 0, 50, 50, MediaQuery.of(context).size.height * 0.9),
// swipeableRightArea: Rect.fromLTWH(
// MediaQuery.of(context).size.width - 50,
// 50,
// 50,
// MediaQuery.of(context).size.height * 0.9),
Comment on lines +270 to +276
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment and add

Suggested change
// swipeableLeftArea: Rect.fromLTWH(
// 0, 50, 50, MediaQuery.of(context).size.height * 0.9),
// swipeableRightArea: Rect.fromLTWH(
// MediaQuery.of(context).size.width - 50,
// 50,
// 50,
// MediaQuery.of(context).size.height * 0.9),
swipeableArea: Rect.fromLTWH(0, 0, MediaQuery.of(context).size.width,

Even without specifying swipeableArea whole width should be swipeable

errorBuilder: (context) {
return const Center(child: Text('Error 404'));
},
Expand Down Expand Up @@ -399,7 +418,7 @@ class FeedTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 300,
height: 400,
margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8),
color: Theme.of(context).colorScheme.surface,
child: Card(
Expand Down Expand Up @@ -459,6 +478,86 @@ class FeedDetail extends StatelessWidget {
}
}

class ProductPage extends ConsumerStatefulWidget {
const ProductPage({super.key});
static const String route = '/';

@override
ConsumerState<ConsumerStatefulWidget> createState() => _ProductPageState();
}

class _ProductPageState extends ConsumerState<ProductPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Products'),
),
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 5,
// controller: _scrollController,
itemBuilder: (context, index) {
return Container(
height: 60,
color: Colors.redAccent.shade100,
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
if (index == 0) {
NavbarNotifier.pushNamed(FeedDetail.route, 0);
NavbarNotifier.showSnackBar(
context, 'switching to Home', onClosed: () {
NavbarNotifier.index = 0;
});
} else {
NavbarNotifier.hideBottomNavBar = false;
Navigate.pushNamed(context, ProductDetail.route,
transitionType: TransitionType.scale,
arguments: {'id': index.toString()});
}
},
child: Card(
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 12),
height: 60,
width: 120,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.all(8),
height: 15,
width: 15,
color: Theme.of(context)
.colorScheme
.secondary,
),
Flexible(
child: Text(
index != 0
? 'Product $index'
: 'Tap to push a route on HomePage Programmatically',
textAlign: TextAlign.end,
),
),
],
)),
)),
);
}),
),
const Expanded(flex: 2, child: ProductList()),
],
));
}
}

class ProductList extends ConsumerStatefulWidget {
const ProductList({super.key});
static const String route = '/';
Expand Down Expand Up @@ -512,34 +611,29 @@ class _ProductListState extends ConsumerState<ProductList> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Products'),
),
body: ListView.builder(
controller: _scrollController,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
if (index == 0) {
NavbarNotifier.pushNamed(FeedDetail.route, 0);
NavbarNotifier.showSnackBar(context, 'switching to Home',
onClosed: () {
NavbarNotifier.index = 0;
});
} else {
NavbarNotifier.hideBottomNavBar = false;
Navigate.pushNamed(context, ProductDetail.route,
transitionType: TransitionType.scale,
arguments: {'id': index.toString()});
}
},
child: ProductTile(index: index)),
);
}),
);
return ListView.builder(
controller: _scrollController,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
if (index == 0) {
NavbarNotifier.pushNamed(FeedDetail.route, 0);
NavbarNotifier.showSnackBar(context, 'switching to Home',
onClosed: () {
NavbarNotifier.index = 0;
});
} else {
NavbarNotifier.hideBottomNavBar = false;
Navigate.pushNamed(context, ProductDetail.route,
transitionType: TransitionType.scale,
arguments: {'id': index.toString()});
}
},
child: ProductTile(index: index)),
);
});
}
}

Expand Down
Loading