Skip to content

Commit

Permalink
Improve recursive routing navigation with 2 FABs
Browse files Browse the repository at this point in the history
  • Loading branch information
TechAurelian committed Oct 31, 2024
1 parent 2f7d77e commit eac7668
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
5 changes: 3 additions & 2 deletions recursive_routing/lib/common/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ library;
const String appName = 'Flutter Recursive Routing';
const String recursiveRoutingScreenTitle = 'Recursive Routing';
String recursiveLevel(int level) => 'Level $level';
const String goHomeTitle = 'Go home';
const String goDeeperTitle = 'Go deeper';
const String goHomeTitle = 'Go back to the first level';
const String goUpTooltip = 'Go up to the previous level';
const String goDownTooltip = 'Go down to the next level';
const String addTooltip = 'Increment counter to check state keeping';
40 changes: 32 additions & 8 deletions recursive_routing/lib/screens/recursive_routing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _RecursiveRoutingScreenState extends State<RecursiveRoutingScreen> {
}

/// Navigates to a deeper recursive routing screen.
void _goDeep() {
void _goDown() {
Navigator.push(
context,
MaterialPageRoute(
Expand All @@ -56,6 +56,11 @@ class _RecursiveRoutingScreenState extends State<RecursiveRoutingScreen> {
);
}

/// Navigates to a shallower recursive routing screen.
void _goUp() {
if (widget.level > 1) Navigator.pop(context);
}

/// Performs the tasks of the app bar actions.
void _onAppBarAction(_AppBarActions action) {
switch (action) {
Expand Down Expand Up @@ -92,13 +97,32 @@ class _RecursiveRoutingScreenState extends State<RecursiveRoutingScreen> {
),
),

// The floating action button that navigates to a deeper recursive routing screen
floatingActionButton: FloatingActionButton.extended(
backgroundColor: _accentColor,
foregroundColor: contrastColor,
onPressed: _goDeep,
icon: const Icon(Icons.arrow_drop_down_circle),
label: const Text(strings.goDeeperTitle),
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// The floating action button that navigates to a shallower recursive routing screen
if (widget.level > 1) ...[
FloatingActionButton.large(
heroTag: 'goUp',
backgroundColor: _accentColor,
foregroundColor: contrastColor,
tooltip: strings.goUpTooltip,
onPressed: _goUp,
child: const Icon(Icons.arrow_back),
),
const SizedBox(width: 16.0),
],

// The floating action button that navigates to a deeper recursive routing screen
FloatingActionButton.large(
heroTag: 'goDown',
backgroundColor: _accentColor,
foregroundColor: contrastColor,
tooltip: strings.goDownTooltip,
onPressed: _goDown,
child: const Icon(Icons.arrow_forward),
),
],
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions recursive_routing/lib/utils/color_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'dart:math';
import 'package:flutter/material.dart';

/// A random number generator used to generate random colors.
final Random _random = Random();
final Random _random = Random.secure();

/// Generates a random color.
Color getRandomColor() {
return Color.fromRGBO(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256), 1.0);
return Color(0xFF000000 + _random.nextInt(0x1000000));
}

/// Returns an appropriate contast color for the given color (black or white).
Expand Down

0 comments on commit eac7668

Please sign in to comment.