-
Notifications
You must be signed in to change notification settings - Fork 8
Add Swipe support between navbar pages #55
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
Open
bebaoboy
wants to merge
11
commits into
maheshj01:main
Choose a base branch
from
bebaoboy:issue-42-swipe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5b62253
first commit
bebaoboy e41ae50
finish base feature
bebaoboy 6ff7e3d
Merge branch 'issue-42-swipe' into main
bebaoboy 1116ba7
Merge pull request #1 from bebaoboy/main
bebaoboy f358ec4
add variables to control swipe + update example app
bebaoboy 2b93618
added tests
bebaoboy 4652402
make docs more clear
bebaoboy 7953798
fix landscape mode
bebaoboy f55c3e1
update as requested:
bebaoboy 34a1131
minor fix
bebaoboy 74066a9
Merge branch 'main' into issue-42-swipe
bebaoboy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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(), | ||||||||||||||||||
| }, | ||||||||||||||||||
|
|
@@ -193,7 +194,7 @@ class _HomePageState extends ConsumerState<HomePage> { | |||||||||||||||||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||||||||||||||||
| children: [ | ||||||||||||||||||
| const SizedBox( | ||||||||||||||||||
| width: 100, | ||||||||||||||||||
| width: 50, | ||||||||||||||||||
| ), | ||||||||||||||||||
| FloatingActionButton.extended( | ||||||||||||||||||
| heroTag: 'showSnackBar', | ||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||
|
|
@@ -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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this comment and add
Suggested change
Even without specifying |
||||||||||||||||||
| errorBuilder: (context) { | ||||||||||||||||||
| return const Center(child: Text('Error 404')); | ||||||||||||||||||
| }, | ||||||||||||||||||
|
|
@@ -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( | ||||||||||||||||||
|
|
@@ -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 = '/'; | ||||||||||||||||||
|
|
@@ -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)), | ||||||||||||||||||
| ); | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.