1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +00:00
Files
samples/navigation_and_routing/lib/src/screens/scaffold.dart
Kevin Moore ecf716dcab navigation_and_routing: a bunch of cleanup (#886)
Fail early on nullable context objects - no code paths allow null
Eliminate superfluous private function
Use a function over an abstract class with one method
2021-08-26 16:14:29 -07:00

55 lines
1.6 KiB
Dart

// Copyright 2021, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:adaptive_navigation/adaptive_navigation.dart';
import 'package:flutter/material.dart';
import '../routing.dart';
import 'scaffold_body.dart';
class BookstoreScaffold extends StatelessWidget {
const BookstoreScaffold({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final routeState = RouteStateScope.of(context);
final selectedIndex = _getSelectedIndex(routeState.route.pathTemplate);
return Scaffold(
body: AdaptiveNavigationScaffold(
selectedIndex: selectedIndex,
body: const BookstoreScaffoldBody(),
onDestinationSelected: (idx) {
if (idx == 0) routeState.go('/books/popular');
if (idx == 1) routeState.go('/authors');
if (idx == 2) routeState.go('/settings');
},
destinations: const [
AdaptiveScaffoldDestination(
title: 'Books',
icon: Icons.book,
),
AdaptiveScaffoldDestination(
title: 'Authors',
icon: Icons.person,
),
AdaptiveScaffoldDestination(
title: 'Settings',
icon: Icons.settings,
),
],
),
);
}
int _getSelectedIndex(String pathTemplate) {
if (pathTemplate.startsWith('/books')) return 0;
if (pathTemplate == '/authors') return 1;
if (pathTemplate == '/settings') return 2;
return 0;
}
}