|
|
|
@ -9,7 +9,8 @@ import 'elevation_screen.dart';
|
|
|
|
|
import 'typography_screen.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
runApp(const Material3Demo());
|
|
|
|
|
runApp(const MaterialApp(
|
|
|
|
|
debugShowCheckedModeBanner: false, home: Material3Demo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Material3Demo extends StatefulWidget {
|
|
|
|
@ -23,25 +24,23 @@ class Material3Demo extends StatefulWidget {
|
|
|
|
|
// screenWidthThreshold; otherwise, NavigationBar is used for navigation.
|
|
|
|
|
const double narrowScreenWidthThreshold = 450;
|
|
|
|
|
|
|
|
|
|
const Color m3BaseColor = Color(0xff6750a4);
|
|
|
|
|
const List<Color> colorOptions = [
|
|
|
|
|
m3BaseColor,
|
|
|
|
|
Colors.blue,
|
|
|
|
|
Colors.teal,
|
|
|
|
|
Colors.green,
|
|
|
|
|
Colors.yellow,
|
|
|
|
|
Colors.orange,
|
|
|
|
|
Colors.pink
|
|
|
|
|
];
|
|
|
|
|
const List<String> colorText = <String>[
|
|
|
|
|
'M3 Baseline',
|
|
|
|
|
'Blue',
|
|
|
|
|
'Teal',
|
|
|
|
|
'Green',
|
|
|
|
|
'Yellow',
|
|
|
|
|
'Orange',
|
|
|
|
|
'Pink',
|
|
|
|
|
];
|
|
|
|
|
const double transitionLength = 500;
|
|
|
|
|
|
|
|
|
|
enum ColorSeed {
|
|
|
|
|
baseColor('M3 Baseline', Color(0xff6750a4)),
|
|
|
|
|
indigo('Indigo', Colors.indigo),
|
|
|
|
|
blue('Blue', Colors.blue),
|
|
|
|
|
teal('Teal', Colors.teal),
|
|
|
|
|
green('Green', Colors.green),
|
|
|
|
|
yellow('Yellow', Colors.yellow),
|
|
|
|
|
orange('Orange', Colors.orange),
|
|
|
|
|
deepOrange('Deep Orange', Colors.deepOrange),
|
|
|
|
|
pink('Pink', Colors.pink);
|
|
|
|
|
|
|
|
|
|
const ColorSeed(this.label, this.color);
|
|
|
|
|
final String label;
|
|
|
|
|
final Color color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ScreenSelected {
|
|
|
|
|
component(0),
|
|
|
|
@ -53,10 +52,17 @@ enum ScreenSelected {
|
|
|
|
|
final int value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
class _Material3DemoState extends State<Material3Demo>
|
|
|
|
|
with SingleTickerProviderStateMixin {
|
|
|
|
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
late final AnimationController controller;
|
|
|
|
|
late final CurvedAnimation railAnimation;
|
|
|
|
|
bool controllerInitialized = false;
|
|
|
|
|
bool showMediumSizeLayout = false;
|
|
|
|
|
bool showLargeSizeLayout = false;
|
|
|
|
|
bool useMaterial3 = true;
|
|
|
|
|
bool useLightMode = true;
|
|
|
|
|
int colorSelected = 0;
|
|
|
|
|
ColorSeed colorSelected = ColorSeed.baseColor;
|
|
|
|
|
int screenIndex = ScreenSelected.component.value;
|
|
|
|
|
|
|
|
|
|
late ThemeData themeData;
|
|
|
|
@ -64,12 +70,61 @@ class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
@override
|
|
|
|
|
initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
themeData = updateThemes(colorSelected, useMaterial3, useLightMode);
|
|
|
|
|
themeData = updateThemes(colorSelected.color, useMaterial3, useLightMode);
|
|
|
|
|
|
|
|
|
|
controller = AnimationController(
|
|
|
|
|
duration: Duration(milliseconds: transitionLength.toInt() * 2),
|
|
|
|
|
value: 0,
|
|
|
|
|
vsync: this,
|
|
|
|
|
);
|
|
|
|
|
railAnimation = CurvedAnimation(
|
|
|
|
|
parent: controller,
|
|
|
|
|
curve: const Interval(0.5, 1.0),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
controller.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThemeData updateThemes(int colorIndex, bool useMaterial3, bool useLightMode) {
|
|
|
|
|
@override
|
|
|
|
|
void didChangeDependencies() {
|
|
|
|
|
super.didChangeDependencies();
|
|
|
|
|
|
|
|
|
|
final double width = MediaQuery.of(context).size.width;
|
|
|
|
|
final AnimationStatus status = controller.status;
|
|
|
|
|
if (width > 1000) {
|
|
|
|
|
if (width > 1500) {
|
|
|
|
|
showMediumSizeLayout = false;
|
|
|
|
|
showLargeSizeLayout = true;
|
|
|
|
|
} else {
|
|
|
|
|
showMediumSizeLayout = true;
|
|
|
|
|
showLargeSizeLayout = false;
|
|
|
|
|
}
|
|
|
|
|
if (status != AnimationStatus.forward &&
|
|
|
|
|
status != AnimationStatus.completed) {
|
|
|
|
|
controller.forward();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
showMediumSizeLayout = false;
|
|
|
|
|
showLargeSizeLayout = false;
|
|
|
|
|
if (status != AnimationStatus.reverse &&
|
|
|
|
|
status != AnimationStatus.dismissed) {
|
|
|
|
|
controller.reverse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!controllerInitialized) {
|
|
|
|
|
controllerInitialized = true;
|
|
|
|
|
controller.value = width > 1000 ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThemeData updateThemes(
|
|
|
|
|
Color colorSelected, bool useMaterial3, bool useLightMode) {
|
|
|
|
|
return ThemeData(
|
|
|
|
|
colorSchemeSeed: colorOptions[colorSelected],
|
|
|
|
|
colorSchemeSeed: colorSelected,
|
|
|
|
|
useMaterial3: useMaterial3,
|
|
|
|
|
brightness: useLightMode ? Brightness.light : Brightness.dark);
|
|
|
|
|
}
|
|
|
|
@ -83,21 +138,21 @@ class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
void handleBrightnessChange() {
|
|
|
|
|
setState(() {
|
|
|
|
|
useLightMode = !useLightMode;
|
|
|
|
|
themeData = updateThemes(colorSelected, useMaterial3, useLightMode);
|
|
|
|
|
themeData = updateThemes(colorSelected.color, useMaterial3, useLightMode);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleMaterialVersionChange() {
|
|
|
|
|
setState(() {
|
|
|
|
|
useMaterial3 = !useMaterial3;
|
|
|
|
|
themeData = updateThemes(colorSelected, useMaterial3, useLightMode);
|
|
|
|
|
themeData = updateThemes(colorSelected.color, useMaterial3, useLightMode);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleColorSelect(int value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
colorSelected = value;
|
|
|
|
|
themeData = updateThemes(colorSelected, useMaterial3, useLightMode);
|
|
|
|
|
colorSelected = ColorSeed.values[value];
|
|
|
|
|
themeData = updateThemes(colorSelected.color, useMaterial3, useLightMode);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -105,7 +160,15 @@ class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
ScreenSelected screenSelected, bool showNavBarExample) {
|
|
|
|
|
switch (screenSelected) {
|
|
|
|
|
case ScreenSelected.component:
|
|
|
|
|
return ComponentScreen(showNavBottomBar: showNavBarExample);
|
|
|
|
|
return Expanded(
|
|
|
|
|
child: OneTwoTransition(
|
|
|
|
|
animation: railAnimation,
|
|
|
|
|
one: FirstComponentList(
|
|
|
|
|
showNavBottomBar: showNavBarExample,
|
|
|
|
|
scaffoldKey: scaffoldKey,
|
|
|
|
|
showSecondList:
|
|
|
|
|
showMediumSizeLayout || showLargeSizeLayout),
|
|
|
|
|
two: const SecondComponentList()));
|
|
|
|
|
case ScreenSelected.color:
|
|
|
|
|
return const ColorPalettesScreen();
|
|
|
|
|
case ScreenSelected.typography:
|
|
|
|
@ -113,62 +176,140 @@ class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
case ScreenSelected.elevation:
|
|
|
|
|
return const ElevationScreen();
|
|
|
|
|
default:
|
|
|
|
|
return ComponentScreen(showNavBottomBar: showNavBarExample);
|
|
|
|
|
return FirstComponentList(
|
|
|
|
|
showNavBottomBar: showNavBarExample,
|
|
|
|
|
scaffoldKey: scaffoldKey,
|
|
|
|
|
showSecondList: showMediumSizeLayout || showLargeSizeLayout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreferredSizeWidget createAppBar() {
|
|
|
|
|
return AppBar(
|
|
|
|
|
title: useMaterial3 ? const Text('Material 3') : const Text('Material 2'),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
Widget brightnessButton({bool showTooltipBelow = true}) => Tooltip(
|
|
|
|
|
preferBelow: showTooltipBelow,
|
|
|
|
|
message: 'Toggle brightness',
|
|
|
|
|
child: IconButton(
|
|
|
|
|
icon: useLightMode
|
|
|
|
|
? const Icon(Icons.wb_sunny_outlined)
|
|
|
|
|
: const Icon(Icons.wb_sunny),
|
|
|
|
|
onPressed: handleBrightnessChange,
|
|
|
|
|
tooltip: 'Toggle brightness',
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Widget material3Button({bool showTooltipBelow = true}) => Tooltip(
|
|
|
|
|
preferBelow: showTooltipBelow,
|
|
|
|
|
message: 'Switch to Material ${useMaterial3 ? 2 : 3}',
|
|
|
|
|
child: IconButton(
|
|
|
|
|
icon: useMaterial3
|
|
|
|
|
? const Icon(Icons.filter_3)
|
|
|
|
|
: const Icon(Icons.filter_2),
|
|
|
|
|
onPressed: handleMaterialVersionChange,
|
|
|
|
|
tooltip: 'Switch to Material ${useMaterial3 ? 2 : 3}',
|
|
|
|
|
),
|
|
|
|
|
PopupMenuButton(
|
|
|
|
|
icon: const Icon(Icons.more_vert),
|
|
|
|
|
shape:
|
|
|
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
|
|
|
itemBuilder: (context) {
|
|
|
|
|
return List.generate(colorOptions.length, (index) {
|
|
|
|
|
return PopupMenuItem(
|
|
|
|
|
value: index,
|
|
|
|
|
child: Wrap(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 10),
|
|
|
|
|
child: Icon(
|
|
|
|
|
index == colorSelected
|
|
|
|
|
? Icons.color_lens
|
|
|
|
|
: Icons.color_lens_outlined,
|
|
|
|
|
color: colorOptions[index],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
|
child: Text(colorText[index]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Widget colorSeedButton(Icon icon) => PopupMenuButton(
|
|
|
|
|
icon: icon,
|
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
|
|
|
itemBuilder: (context) {
|
|
|
|
|
return List.generate(ColorSeed.values.length, (index) {
|
|
|
|
|
ColorSeed currentColor = ColorSeed.values[index];
|
|
|
|
|
|
|
|
|
|
return PopupMenuItem(
|
|
|
|
|
value: index,
|
|
|
|
|
child: Wrap(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 10),
|
|
|
|
|
child: Icon(
|
|
|
|
|
currentColor == colorSelected
|
|
|
|
|
? Icons.color_lens
|
|
|
|
|
: Icons.color_lens_outlined,
|
|
|
|
|
color: currentColor.color,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onSelected: handleColorSelect,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
|
child: Text(currentColor.label),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onSelected: handleColorSelect,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
PreferredSizeWidget createAppBar() {
|
|
|
|
|
return AppBar(
|
|
|
|
|
title: useMaterial3 ? const Text('Material 3') : const Text('Material 2'),
|
|
|
|
|
actions: !showMediumSizeLayout && !showLargeSizeLayout
|
|
|
|
|
? [
|
|
|
|
|
brightnessButton(),
|
|
|
|
|
material3Button(),
|
|
|
|
|
colorSeedButton(const Icon(Icons.more_vert)),
|
|
|
|
|
]
|
|
|
|
|
: [Container()],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _expandedTrailingActions() => Container(
|
|
|
|
|
constraints: const BoxConstraints.tightFor(width: 250),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
const Text('Brightness'),
|
|
|
|
|
Expanded(child: Container()),
|
|
|
|
|
Switch(
|
|
|
|
|
value: useLightMode,
|
|
|
|
|
onChanged: (_) {
|
|
|
|
|
handleBrightnessChange();
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
useMaterial3
|
|
|
|
|
? const Text('Material 3')
|
|
|
|
|
: const Text('Material 2'),
|
|
|
|
|
Expanded(child: Container()),
|
|
|
|
|
Switch(
|
|
|
|
|
value: useMaterial3,
|
|
|
|
|
onChanged: (_) {
|
|
|
|
|
handleMaterialVersionChange();
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const Divider(),
|
|
|
|
|
ConstrainedBox(
|
|
|
|
|
constraints: const BoxConstraints(maxHeight: 200.0),
|
|
|
|
|
child: GridView.count(
|
|
|
|
|
crossAxisCount: 3,
|
|
|
|
|
children: List.generate(
|
|
|
|
|
ColorSeed.values.length,
|
|
|
|
|
(i) => IconButton(
|
|
|
|
|
icon: const Icon(Icons.circle),
|
|
|
|
|
color: ColorSeed.values[i].color,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
handleColorSelect(i);
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Widget _trailingActions() => Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(child: brightnessButton(showTooltipBelow: false)),
|
|
|
|
|
Flexible(child: material3Button(showTooltipBelow: false)),
|
|
|
|
|
Flexible(child: colorSeedButton(const Icon(Icons.more_horiz))),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
@ -176,40 +317,337 @@ class _Material3DemoState extends State<Material3Demo> {
|
|
|
|
|
title: 'Material 3',
|
|
|
|
|
themeMode: useLightMode ? ThemeMode.light : ThemeMode.dark,
|
|
|
|
|
theme: themeData,
|
|
|
|
|
home: LayoutBuilder(builder: (context, constraints) {
|
|
|
|
|
if (constraints.maxWidth < narrowScreenWidthThreshold) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: createAppBar(),
|
|
|
|
|
body: Row(children: <Widget>[
|
|
|
|
|
createScreenFor(ScreenSelected.values[screenIndex], false),
|
|
|
|
|
]),
|
|
|
|
|
bottomNavigationBar: NavigationBars(
|
|
|
|
|
onSelectItem: handleScreenChanged,
|
|
|
|
|
selectedIndex: screenIndex,
|
|
|
|
|
isExampleBar: false,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: createAppBar(),
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
bottom: false,
|
|
|
|
|
top: false,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 5),
|
|
|
|
|
child: NavigationRailSection(
|
|
|
|
|
onSelectItem: handleScreenChanged,
|
|
|
|
|
selectedIndex: screenIndex)),
|
|
|
|
|
const VerticalDivider(thickness: 1, width: 1),
|
|
|
|
|
createScreenFor(ScreenSelected.values[screenIndex], true),
|
|
|
|
|
],
|
|
|
|
|
home: AnimatedBuilder(
|
|
|
|
|
animation: controller,
|
|
|
|
|
builder: (context, child) {
|
|
|
|
|
return NavigationTransition(
|
|
|
|
|
scaffoldKey: scaffoldKey,
|
|
|
|
|
animationController: controller,
|
|
|
|
|
railAnimation: railAnimation,
|
|
|
|
|
appBar: createAppBar(),
|
|
|
|
|
body: createScreenFor(
|
|
|
|
|
ScreenSelected.values[screenIndex], controller.value == 1),
|
|
|
|
|
navigationRail: NavigationRail(
|
|
|
|
|
extended: showLargeSizeLayout,
|
|
|
|
|
destinations: navRailDestinations,
|
|
|
|
|
selectedIndex: screenIndex,
|
|
|
|
|
onDestinationSelected: (index) {
|
|
|
|
|
setState(() {
|
|
|
|
|
screenIndex = index;
|
|
|
|
|
handleScreenChanged(screenIndex);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
trailing: Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 20),
|
|
|
|
|
child: showLargeSizeLayout
|
|
|
|
|
? _expandedTrailingActions()
|
|
|
|
|
: _trailingActions(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
navigationBar: NavigationBars(
|
|
|
|
|
onSelectItem: (index) {
|
|
|
|
|
setState(() {
|
|
|
|
|
screenIndex = index;
|
|
|
|
|
handleScreenChanged(screenIndex);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
selectedIndex: screenIndex,
|
|
|
|
|
isExampleBar: false,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NavigationTransition extends StatefulWidget {
|
|
|
|
|
const NavigationTransition(
|
|
|
|
|
{super.key,
|
|
|
|
|
required this.scaffoldKey,
|
|
|
|
|
required this.animationController,
|
|
|
|
|
required this.railAnimation,
|
|
|
|
|
required this.navigationRail,
|
|
|
|
|
required this.navigationBar,
|
|
|
|
|
required this.appBar,
|
|
|
|
|
required this.body});
|
|
|
|
|
|
|
|
|
|
final GlobalKey<ScaffoldState> scaffoldKey;
|
|
|
|
|
final AnimationController animationController;
|
|
|
|
|
final CurvedAnimation railAnimation;
|
|
|
|
|
final Widget navigationRail;
|
|
|
|
|
final Widget navigationBar;
|
|
|
|
|
final PreferredSizeWidget appBar;
|
|
|
|
|
final Widget body;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<NavigationTransition> createState() => _NavigationTransitionState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _NavigationTransitionState extends State<NavigationTransition> {
|
|
|
|
|
late final AnimationController controller;
|
|
|
|
|
late final CurvedAnimation railAnimation;
|
|
|
|
|
late final ReverseAnimation barAnimation;
|
|
|
|
|
bool controllerInitialized = false;
|
|
|
|
|
bool showDivider = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
controller = widget.animationController;
|
|
|
|
|
railAnimation = widget.railAnimation;
|
|
|
|
|
|
|
|
|
|
barAnimation = ReverseAnimation(
|
|
|
|
|
CurvedAnimation(
|
|
|
|
|
parent: controller,
|
|
|
|
|
curve: const Interval(0.0, 0.5),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final ColorScheme colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
key: widget.scaffoldKey,
|
|
|
|
|
appBar: widget.appBar,
|
|
|
|
|
body: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
RailTransition(
|
|
|
|
|
animation: railAnimation,
|
|
|
|
|
backgroundColor: colorScheme.surface,
|
|
|
|
|
child: widget.navigationRail,
|
|
|
|
|
),
|
|
|
|
|
railAnimation.isDismissed
|
|
|
|
|
? const SizedBox()
|
|
|
|
|
: const VerticalDivider(width: 1),
|
|
|
|
|
widget.body,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
bottomNavigationBar: BarTransition(
|
|
|
|
|
animation: barAnimation,
|
|
|
|
|
backgroundColor: colorScheme.surface,
|
|
|
|
|
child: widget.navigationBar,
|
|
|
|
|
),
|
|
|
|
|
endDrawer: const NavigationDrawerSection(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final List<NavigationRailDestination> navRailDestinations = appBarDestinations
|
|
|
|
|
.map(
|
|
|
|
|
(destination) => NavigationRailDestination(
|
|
|
|
|
icon: Tooltip(
|
|
|
|
|
message: destination.label,
|
|
|
|
|
child: destination.icon,
|
|
|
|
|
),
|
|
|
|
|
selectedIcon: Tooltip(
|
|
|
|
|
message: destination.label,
|
|
|
|
|
child: destination.selectedIcon,
|
|
|
|
|
),
|
|
|
|
|
label: Text(destination.label),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
class SizeAnimation extends CurvedAnimation {
|
|
|
|
|
SizeAnimation(Animation<double> parent)
|
|
|
|
|
: super(
|
|
|
|
|
parent: parent,
|
|
|
|
|
curve: const Interval(
|
|
|
|
|
0.2,
|
|
|
|
|
0.8,
|
|
|
|
|
curve: Curves.easeInOutCubicEmphasized,
|
|
|
|
|
),
|
|
|
|
|
reverseCurve: Interval(
|
|
|
|
|
0,
|
|
|
|
|
0.2,
|
|
|
|
|
curve: Curves.easeInOutCubicEmphasized.flipped,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OffsetAnimation extends CurvedAnimation {
|
|
|
|
|
OffsetAnimation(Animation<double> parent)
|
|
|
|
|
: super(
|
|
|
|
|
parent: parent,
|
|
|
|
|
curve: const Interval(
|
|
|
|
|
0.4,
|
|
|
|
|
1.0,
|
|
|
|
|
curve: Curves.easeInOutCubicEmphasized,
|
|
|
|
|
),
|
|
|
|
|
reverseCurve: Interval(
|
|
|
|
|
0,
|
|
|
|
|
0.2,
|
|
|
|
|
curve: Curves.easeInOutCubicEmphasized.flipped,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RailTransition extends StatefulWidget {
|
|
|
|
|
const RailTransition(
|
|
|
|
|
{super.key,
|
|
|
|
|
required this.animation,
|
|
|
|
|
required this.backgroundColor,
|
|
|
|
|
required this.child});
|
|
|
|
|
|
|
|
|
|
final Animation<double> animation;
|
|
|
|
|
final Widget child;
|
|
|
|
|
final Color backgroundColor;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<RailTransition> createState() => _RailTransition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _RailTransition extends State<RailTransition> {
|
|
|
|
|
late Animation<Offset> offsetAnimation;
|
|
|
|
|
late Animation<double> widthAnimation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didChangeDependencies() {
|
|
|
|
|
super.didChangeDependencies();
|
|
|
|
|
|
|
|
|
|
// The animations are only rebuilt by this method when the text
|
|
|
|
|
// direction changes because this widget only depends on Directionality.
|
|
|
|
|
final bool ltr = Directionality.of(context) == TextDirection.ltr;
|
|
|
|
|
|
|
|
|
|
widthAnimation = Tween<double>(
|
|
|
|
|
begin: 0,
|
|
|
|
|
end: 1,
|
|
|
|
|
).animate(SizeAnimation(widget.animation));
|
|
|
|
|
|
|
|
|
|
offsetAnimation = Tween<Offset>(
|
|
|
|
|
begin: ltr ? const Offset(-1, 0) : const Offset(1, 0),
|
|
|
|
|
end: Offset.zero,
|
|
|
|
|
).animate(OffsetAnimation(widget.animation));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return ClipRect(
|
|
|
|
|
child: DecoratedBox(
|
|
|
|
|
decoration: BoxDecoration(color: widget.backgroundColor),
|
|
|
|
|
child: Align(
|
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
|
widthFactor: widthAnimation.value,
|
|
|
|
|
child: FractionalTranslation(
|
|
|
|
|
translation: offsetAnimation.value,
|
|
|
|
|
child: widget.child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BarTransition extends StatefulWidget {
|
|
|
|
|
const BarTransition(
|
|
|
|
|
{super.key,
|
|
|
|
|
required this.animation,
|
|
|
|
|
required this.backgroundColor,
|
|
|
|
|
required this.child});
|
|
|
|
|
|
|
|
|
|
final Animation<double> animation;
|
|
|
|
|
final Color backgroundColor;
|
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<BarTransition> createState() => _BarTransition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _BarTransition extends State<BarTransition> {
|
|
|
|
|
late final Animation<Offset> offsetAnimation;
|
|
|
|
|
late final Animation<double> heightAnimation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
offsetAnimation = Tween<Offset>(
|
|
|
|
|
begin: const Offset(0, 1),
|
|
|
|
|
end: Offset.zero,
|
|
|
|
|
).animate(OffsetAnimation(widget.animation));
|
|
|
|
|
|
|
|
|
|
heightAnimation = Tween<double>(
|
|
|
|
|
begin: 0,
|
|
|
|
|
end: 1,
|
|
|
|
|
).animate(SizeAnimation(widget.animation));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return ClipRect(
|
|
|
|
|
child: DecoratedBox(
|
|
|
|
|
decoration: BoxDecoration(color: widget.backgroundColor),
|
|
|
|
|
child: Align(
|
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
|
heightFactor: heightAnimation.value,
|
|
|
|
|
child: FractionalTranslation(
|
|
|
|
|
translation: offsetAnimation.value,
|
|
|
|
|
child: widget.child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OneTwoTransition extends StatefulWidget {
|
|
|
|
|
const OneTwoTransition({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.animation,
|
|
|
|
|
required this.one,
|
|
|
|
|
required this.two,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final Animation<double> animation;
|
|
|
|
|
final Widget one;
|
|
|
|
|
final Widget two;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<OneTwoTransition> createState() => _OneTwoTransitionState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OneTwoTransitionState extends State<OneTwoTransition> {
|
|
|
|
|
late final Animation<Offset> offsetAnimation;
|
|
|
|
|
late final Animation<double> widthAnimation;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
offsetAnimation = Tween<Offset>(
|
|
|
|
|
begin: const Offset(1, 0),
|
|
|
|
|
end: Offset.zero,
|
|
|
|
|
).animate(OffsetAnimation(widget.animation));
|
|
|
|
|
|
|
|
|
|
widthAnimation = Tween<double>(
|
|
|
|
|
begin: 0,
|
|
|
|
|
end: 1000,
|
|
|
|
|
).animate(SizeAnimation(widget.animation));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Flexible(
|
|
|
|
|
flex: 1000,
|
|
|
|
|
child: widget.one,
|
|
|
|
|
),
|
|
|
|
|
if (widthAnimation.value.toInt() > 0) ...[
|
|
|
|
|
Flexible(
|
|
|
|
|
flex: widthAnimation.value.toInt(),
|
|
|
|
|
child: FractionalTranslation(
|
|
|
|
|
translation: offsetAnimation.value,
|
|
|
|
|
child: widget.two,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|