mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 06:18:49 +00:00
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
55 lines
1.6 KiB
Dart
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;
|
|
}
|
|
}
|