Skip to content

Commit

Permalink
ConditionalRouteWidget from updated navigation_utils and TextButton d…
Browse files Browse the repository at this point in the history
…eprecation updates.
  • Loading branch information
Lee Parayno authored and rayliverified committed Jun 15, 2023
1 parent f85e696 commit a4a74ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/components/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class TextBlockquote extends StatelessWidget {
}

ButtonStyle? menuButtonStyle = TextButton.styleFrom(
foregroundColor: textSecondary,
backgroundColor: Colors.transparent,
onSurface: null,
primary: textSecondary,
disabledForegroundColor: const Color.fromRGBO(
0, 0, 0, 0.38), // Replace null with desired color and opacity
textStyle: buttonTextStyle,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16));
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:minimal/pages/pages.dart';
import 'package:minimal/routes.dart';
import 'package:navigation_utils/navigation_utils.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:minimal/utils/conditional_route_widget.dart';

void main() {
runApp(const MyApp());
Expand Down
32 changes: 32 additions & 0 deletions lib/utils/conditional_route_widget.dart
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;
}
}

0 comments on commit a4a74ec

Please sign in to comment.