|
| 1 | +animate_icons: ^2.0.0 |
| 2 | + |
| 3 | +------------------------------------------------------------------- |
| 4 | + |
| 5 | +animations: ^2.0.0 |
| 6 | + |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter/scheduler.dart'; |
| 9 | + |
| 10 | +import 'container_transition.dart'; |
| 11 | +import 'fade_scale_transition.dart'; |
| 12 | +import 'fade_through_transition.dart'; |
| 13 | +import 'shared_axis_transition.dart'; |
| 14 | + |
| 15 | +void main() { |
| 16 | + runApp( |
| 17 | + MaterialApp( |
| 18 | + theme: ThemeData.from( |
| 19 | + colorScheme: const ColorScheme.light(), |
| 20 | + ).copyWith( |
| 21 | + pageTransitionsTheme: const PageTransitionsTheme( |
| 22 | + builders: <TargetPlatform, PageTransitionsBuilder>{ |
| 23 | + TargetPlatform.android: ZoomPageTransitionsBuilder(), |
| 24 | + }, |
| 25 | + ), |
| 26 | + ), |
| 27 | + home: _TransitionsHomePage(), |
| 28 | + ), |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +class _TransitionsHomePage extends StatefulWidget { |
| 33 | + @override |
| 34 | + _TransitionsHomePageState createState() => _TransitionsHomePageState(); |
| 35 | +} |
| 36 | + |
| 37 | +class _TransitionsHomePageState extends State<_TransitionsHomePage> { |
| 38 | + bool _slowAnimations = false; |
| 39 | + |
| 40 | + @override |
| 41 | + Widget build(BuildContext context) { |
| 42 | + return Scaffold( |
| 43 | + appBar: AppBar(title: const Text('Material Transitions')), |
| 44 | + body: Column( |
| 45 | + children: <Widget>[ |
| 46 | + Expanded( |
| 47 | + child: ListView( |
| 48 | + children: <Widget>[ |
| 49 | + _TransitionListTile( |
| 50 | + title: 'Container transform', |
| 51 | + subtitle: 'OpenContainer', |
| 52 | + onTap: () { |
| 53 | + Navigator.of(context).push( |
| 54 | + MaterialPageRoute<void>( |
| 55 | + builder: (BuildContext context) { |
| 56 | + return OpenContainerTransformDemo(); |
| 57 | + }, |
| 58 | + ), |
| 59 | + ); |
| 60 | + }, |
| 61 | + ), |
| 62 | + _TransitionListTile( |
| 63 | + title: 'Shared axis', |
| 64 | + subtitle: 'SharedAxisTransition', |
| 65 | + onTap: () { |
| 66 | + Navigator.of(context).push( |
| 67 | + MaterialPageRoute<void>( |
| 68 | + builder: (BuildContext context) { |
| 69 | + return SharedAxisTransitionDemo(); |
| 70 | + }, |
| 71 | + ), |
| 72 | + ); |
| 73 | + }, |
| 74 | + ), |
| 75 | + _TransitionListTile( |
| 76 | + title: 'Fade through', |
| 77 | + subtitle: 'FadeThroughTransition', |
| 78 | + onTap: () { |
| 79 | + Navigator.of(context).push( |
| 80 | + MaterialPageRoute<void>( |
| 81 | + builder: (BuildContext context) { |
| 82 | + return FadeThroughTransitionDemo(); |
| 83 | + }, |
| 84 | + ), |
| 85 | + ); |
| 86 | + }, |
| 87 | + ), |
| 88 | + _TransitionListTile( |
| 89 | + title: 'Fade', |
| 90 | + subtitle: 'FadeScaleTransition', |
| 91 | + onTap: () { |
| 92 | + Navigator.of(context).push( |
| 93 | + MaterialPageRoute<void>( |
| 94 | + builder: (BuildContext context) { |
| 95 | + return FadeScaleTransitionDemo(); |
| 96 | + }, |
| 97 | + ), |
| 98 | + ); |
| 99 | + }, |
| 100 | + ), |
| 101 | + ], |
| 102 | + ), |
| 103 | + ), |
| 104 | + const Divider(height: 0.0), |
| 105 | + SafeArea( |
| 106 | + child: SwitchListTile( |
| 107 | + value: _slowAnimations, |
| 108 | + onChanged: (bool value) async { |
| 109 | + setState(() { |
| 110 | + _slowAnimations = value; |
| 111 | + }); |
| 112 | + // Wait until the Switch is done animating before actually slowing |
| 113 | + // down time. |
| 114 | + if (_slowAnimations) { |
| 115 | + await Future<void>.delayed(const Duration(milliseconds: 300)); |
| 116 | + } |
| 117 | + timeDilation = _slowAnimations ? 20.0 : 1.0; |
| 118 | + }, |
| 119 | + title: const Text('Slow animations'), |
| 120 | + ), |
| 121 | + ), |
| 122 | + ], |
| 123 | + ), |
| 124 | + ); |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +class _TransitionListTile extends StatelessWidget { |
| 129 | + const _TransitionListTile({ |
| 130 | + this.onTap, |
| 131 | + required this.title, |
| 132 | + required this.subtitle, |
| 133 | + }); |
| 134 | + |
| 135 | + final GestureTapCallback? onTap; |
| 136 | + final String title; |
| 137 | + final String subtitle; |
| 138 | + |
| 139 | + @override |
| 140 | + Widget build(BuildContext context) { |
| 141 | + return ListTile( |
| 142 | + contentPadding: const EdgeInsets.symmetric( |
| 143 | + horizontal: 15.0, |
| 144 | + ), |
| 145 | + leading: Container( |
| 146 | + width: 40.0, |
| 147 | + height: 40.0, |
| 148 | + decoration: BoxDecoration( |
| 149 | + borderRadius: BorderRadius.circular(20.0), |
| 150 | + border: Border.all( |
| 151 | + color: Colors.black54, |
| 152 | + ), |
| 153 | + ), |
| 154 | + child: const Icon( |
| 155 | + Icons.play_arrow, |
| 156 | + size: 35, |
| 157 | + ), |
| 158 | + ), |
| 159 | + onTap: onTap, |
| 160 | + title: Text(title), |
| 161 | + subtitle: Text(subtitle), |
| 162 | + ); |
| 163 | + } |
| 164 | +} |
0 commit comments