forked from Codelessly/FlutterMinimalWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConditionalRouteWidget from updated navigation_utils and TextButton d…
…eprecation updates.
- Loading branch information
1 parent
f85e696
commit a4a74ec
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ConditionalRouteWidget extends StatelessWidget { | ||
final List<String>? routes; | ||
final List<String>? routesExcluded; | ||
final TransitionBuilder builder; | ||
final Widget child; | ||
|
||
const ConditionalRouteWidget( | ||
{Key? key, | ||
this.routes, | ||
this.routesExcluded, | ||
required this.builder, | ||
required this.child}) | ||
: assert(routes == null || routesExcluded == null, | ||
'Cannot include `routes` and `routesExcluded`. Please provide an list of routes to include or exclude, not both.'), | ||
super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
String? currentRoute = ModalRoute.of(context)?.settings.name; | ||
|
||
if (routes != null && routes!.contains(currentRoute)) { | ||
return builder(context, child); | ||
} else if (routesExcluded != null && | ||
routesExcluded!.contains(currentRoute) == false) { | ||
return builder(context, child); | ||
} | ||
|
||
return child; | ||
} | ||
} |