mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
[web_dashboard] Navigation rail update (#356)
* add new navigation_rail, update adaptive_scaffold * add outdated routing_demo * Add AdaptiveScaffold experiment * clean up experimental/ directory * remove web_dashboard from CI script new NavigationRail widget requires the master channel
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Copyright 2020, 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:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:web_dashboard/src/widgets/third_party/adaptive_scaffold.dart';
|
||||
|
||||
void main() {
|
||||
runApp(DashboardWithoutRoutes());
|
||||
}
|
||||
|
||||
class DashboardWithoutRoutes extends StatefulWidget {
|
||||
@override
|
||||
_DashboardWithoutRoutesState createState() => _DashboardWithoutRoutesState();
|
||||
}
|
||||
|
||||
class _DashboardWithoutRoutesState extends State<DashboardWithoutRoutes> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: AdaptiveScaffold(
|
||||
currentIndex: 0,
|
||||
destinations: [
|
||||
AdaptiveScaffoldDestination(title: 'Home', icon: Icons.home),
|
||||
AdaptiveScaffoldDestination(title: 'Metrics', icon: Icons.show_chart),
|
||||
AdaptiveScaffoldDestination(title: 'Settings', icon: Icons.settings),
|
||||
],
|
||||
body: Center(
|
||||
child: Text('Hello, World!'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
|
||||
...widget.destinations.map(
|
||||
(d) => NavigationRailDestination(
|
||||
icon: Icon(d.icon),
|
||||
title: Text(d.title),
|
||||
label: Text(d.title),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
215
experimental/web_dashboard/lib/src/widgets/third_party/navigation_rail_theme.dart
vendored
Normal file
215
experimental/web_dashboard/lib/src/widgets/third_party/navigation_rail_theme.dart
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' show lerpDouble;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'navigation_rail.dart';
|
||||
|
||||
/// Defines default property values for descendant [NavigationRail]
|
||||
/// widgets.
|
||||
///
|
||||
/// Descendant widgets obtain the current [NavigationRailThemeData] object
|
||||
/// using `NavigationRailTheme.of(context)`. Instances of
|
||||
/// [NavigationRailThemeData] can be customized with
|
||||
/// [NavigationRailThemeData.copyWith].
|
||||
///
|
||||
/// Typically a [NavigationRailThemeData] is specified as part of the
|
||||
/// overall [Theme] with [ThemeData.navigationRailTheme].
|
||||
///
|
||||
/// All [NavigationRailThemeData] properties are `null` by default.
|
||||
/// When null, the [NavigationRail] will use the values from [ThemeData]
|
||||
/// if they exist, otherwise it will provide its own defaults.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [ThemeData], which describes the overall theme information for the
|
||||
/// application.
|
||||
class NavigationRailThemeData extends Diagnosticable {
|
||||
/// Creates a theme that can be used for [ThemeData.navigationRailTheme].
|
||||
const NavigationRailThemeData({
|
||||
this.backgroundColor,
|
||||
this.elevation,
|
||||
this.unselectedLabelTextStyle,
|
||||
this.selectedLabelTextStyle,
|
||||
this.unselectedIconTheme,
|
||||
this.selectedIconTheme,
|
||||
this.groupAlignment,
|
||||
this.labelType,
|
||||
});
|
||||
|
||||
/// Color to be used for the unselected, enabled [NavigationRail]'s
|
||||
/// background.
|
||||
final Color backgroundColor;
|
||||
|
||||
/// The z-coordinate to be used for the unselected, enabled
|
||||
/// [NavigationRail]'s elevation foreground.
|
||||
final double elevation;
|
||||
|
||||
/// The style on which to base the destination label, when the destination
|
||||
/// is not selected.
|
||||
final TextStyle unselectedLabelTextStyle;
|
||||
|
||||
/// The style on which to base the destination label, when the destination
|
||||
/// is selected.
|
||||
final TextStyle selectedLabelTextStyle;
|
||||
|
||||
/// The theme on which to base the destination icon, when the destination
|
||||
/// is not selected.
|
||||
final IconThemeData unselectedIconTheme;
|
||||
|
||||
/// The theme on which to base the destination icon, when the destination
|
||||
/// is selected.
|
||||
final IconThemeData selectedIconTheme;
|
||||
|
||||
/// The alignment for the [NavigationRailDestination]s as they are positioned
|
||||
/// within the [NavigationRail].
|
||||
final NavigationRailGroupAlignment groupAlignment;
|
||||
|
||||
/// The type that defines the layout and behavior of the labels in the
|
||||
/// [NavigationRail].
|
||||
final NavigationRailLabelType labelType;
|
||||
|
||||
/// Creates a copy of this object with the given fields replaced with the
|
||||
/// new values.
|
||||
NavigationRailThemeData copyWith({
|
||||
Color backgroundColor,
|
||||
double elevation,
|
||||
TextStyle unselectedLabelTextStyle,
|
||||
TextStyle selectedLabelTextStyle,
|
||||
IconThemeData unselectedIconTheme,
|
||||
IconThemeData selectedIconTheme,
|
||||
NavigationRailGroupAlignment groupAlignment,
|
||||
NavigationRailLabelType labelType,
|
||||
}) {
|
||||
return NavigationRailThemeData(
|
||||
backgroundColor: backgroundColor ?? this.backgroundColor,
|
||||
elevation: elevation ?? this.elevation,
|
||||
unselectedLabelTextStyle: unselectedLabelTextStyle ?? this.unselectedLabelTextStyle,
|
||||
selectedLabelTextStyle: selectedLabelTextStyle ?? this.selectedLabelTextStyle,
|
||||
unselectedIconTheme: unselectedIconTheme ?? this.unselectedIconTheme,
|
||||
selectedIconTheme: selectedIconTheme ?? this.selectedIconTheme,
|
||||
groupAlignment: groupAlignment ?? this.groupAlignment,
|
||||
labelType: labelType ?? this.labelType,
|
||||
);
|
||||
}
|
||||
|
||||
/// Linearly interpolate between two navigation rail themes.
|
||||
///
|
||||
/// If both arguments are null then null is returned.
|
||||
///
|
||||
/// {@macro dart.ui.shadow.lerp}
|
||||
static NavigationRailThemeData lerp(NavigationRailThemeData a, NavigationRailThemeData b, double t) {
|
||||
assert(t != null);
|
||||
if (a == null && b == null)
|
||||
return null;
|
||||
return NavigationRailThemeData(
|
||||
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
|
||||
elevation: lerpDouble(a?.elevation, b?.elevation, t),
|
||||
unselectedLabelTextStyle: TextStyle.lerp(a?.unselectedLabelTextStyle, b?.unselectedLabelTextStyle, t),
|
||||
selectedLabelTextStyle: TextStyle.lerp(a?.selectedLabelTextStyle, b?.selectedLabelTextStyle, t),
|
||||
unselectedIconTheme: IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t),
|
||||
selectedIconTheme: IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t),
|
||||
groupAlignment: t < 0.5 ? a.groupAlignment : b.groupAlignment,
|
||||
labelType: t < 0.5 ? a.labelType : b.labelType,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return hashValues(
|
||||
backgroundColor,
|
||||
elevation,
|
||||
unselectedLabelTextStyle,
|
||||
selectedLabelTextStyle,
|
||||
unselectedIconTheme,
|
||||
selectedIconTheme,
|
||||
groupAlignment,
|
||||
labelType,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other))
|
||||
return true;
|
||||
if (other.runtimeType != runtimeType)
|
||||
return false;
|
||||
return other is NavigationRailThemeData
|
||||
&& other.backgroundColor == backgroundColor
|
||||
&& other.elevation == elevation
|
||||
&& other.unselectedLabelTextStyle == unselectedLabelTextStyle
|
||||
&& other.selectedLabelTextStyle == selectedLabelTextStyle
|
||||
&& other.unselectedIconTheme == unselectedIconTheme
|
||||
&& other.selectedIconTheme == selectedIconTheme
|
||||
&& other.groupAlignment == groupAlignment
|
||||
&& other.labelType == labelType;
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
const NavigationRailThemeData defaultData = NavigationRailThemeData();
|
||||
|
||||
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor));
|
||||
properties.add(DoubleProperty('elevation', elevation, defaultValue: defaultData.elevation));
|
||||
properties.add(DiagnosticsProperty<TextStyle>('unselectedLabelTextStyle', unselectedLabelTextStyle, defaultValue: defaultData.unselectedLabelTextStyle));
|
||||
properties.add(DiagnosticsProperty<TextStyle>('selectedLabelTextStyle', selectedLabelTextStyle, defaultValue: defaultData.selectedLabelTextStyle));
|
||||
properties.add(DiagnosticsProperty<IconThemeData>('unselectedIconTheme', unselectedIconTheme, defaultValue: defaultData.unselectedIconTheme));
|
||||
properties.add(DiagnosticsProperty<IconThemeData>('selectedIconTheme', selectedIconTheme, defaultValue: defaultData.selectedIconTheme));
|
||||
properties.add(DiagnosticsProperty<NavigationRailGroupAlignment>('groupAlignment', groupAlignment, defaultValue: defaultData.groupAlignment));
|
||||
properties.add(DiagnosticsProperty<NavigationRailLabelType>('labelType', labelType, defaultValue: defaultData.labelType));
|
||||
}
|
||||
}
|
||||
|
||||
/// An inherited widget that defines background color, elevation, label text
|
||||
/// style, icon theme, group alignment, and label type parameters for
|
||||
/// [NavigationRail]s in this widget's subtree.
|
||||
///
|
||||
/// Values specified here are used for [NavigationRail] properties that are not
|
||||
/// given an explicit non-null value.
|
||||
class NavigationRailTheme extends InheritedTheme {
|
||||
/// Creates a navigation rail theme that controls the
|
||||
/// [NavigationRailThemeData] properties for a [NavigationRail].
|
||||
///
|
||||
/// The data argument must not be null.
|
||||
const NavigationRailTheme({
|
||||
Key key,
|
||||
@required this.data,
|
||||
Widget child,
|
||||
}) : assert(data != null), super(key: key, child: child);
|
||||
|
||||
/// Specifies the background color, elevation, label text style, icon theme,
|
||||
/// group alignment, and label type and border values for descendant
|
||||
/// [NavigationRail] widgets.
|
||||
final NavigationRailThemeData data;
|
||||
|
||||
/// The closest instance of this class that encloses the given context.
|
||||
///
|
||||
/// If there is no enclosing [NavigationRailTheme] widget, then
|
||||
/// [ThemeData.navigationRailTheme] is used.
|
||||
///
|
||||
/// Typical usage is as follows:
|
||||
///
|
||||
/// ```dart
|
||||
/// NavigationRailTheme theme = NavigationRailTheme.of(context);
|
||||
/// ```
|
||||
static NavigationRailThemeData of(BuildContext context) {
|
||||
final NavigationRailTheme navigationRailTheme = context.dependOnInheritedWidgetOfExactType<NavigationRailTheme>();
|
||||
return navigationRailTheme?.data ?? NavigationRailThemeData(); // ?? Theme.of(context).navigationRailTheme;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget wrap(BuildContext context, Widget child) {
|
||||
final NavigationRailTheme ancestorTheme = context.findAncestorWidgetOfExactType<NavigationRailTheme>();
|
||||
return identical(this, ancestorTheme) ? child : NavigationRailTheme(data: data, child: child);
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(NavigationRailTheme oldWidget) => data != oldWidget.data;
|
||||
}
|
||||
@@ -29,7 +29,6 @@ declare -ar PROJECT_NAMES=(
|
||||
"add_to_app/flutter_module" \
|
||||
"add_to_app/flutter_module_using_plugin" \
|
||||
"animations" \
|
||||
"experimental/web_dashboard" \
|
||||
"flutter_maps_firestore" \
|
||||
"gallery" \
|
||||
"isolate_example" \
|
||||
|
||||
Reference in New Issue
Block a user