|
| 1 | +# Example of usage `auto_animated` |
| 2 | + |
| 3 | +```dart |
| 4 | +import 'package:flutter/material.dart'; |
| 5 | +
|
| 6 | +import 'package:auto_animated/auto_animated.dart'; |
| 7 | +
|
| 8 | +void main() => runApp(MyApp()); |
| 9 | +
|
| 10 | +class MyApp extends StatelessWidget { |
| 11 | + @override |
| 12 | + Widget build(BuildContext context) => MaterialApp( |
| 13 | + home: Scaffold( |
| 14 | + backgroundColor: Colors.grey[100], |
| 15 | + appBar: AppBar( |
| 16 | + title: Text('Auto animated example'), |
| 17 | + ), |
| 18 | + body: Column( |
| 19 | + children: <Widget>[ |
| 20 | + SizedBox( |
| 21 | + height: 200, |
| 22 | + child: AutoAnimatedList( |
| 23 | + showItemInterval: Duration(milliseconds: 500), |
| 24 | + showItemDuration: Duration(seconds: 1), |
| 25 | + padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 24), |
| 26 | + scrollDirection: Axis.horizontal, |
| 27 | + itemsCount: 10, |
| 28 | + itemBuilder: _buildAnimatedItem, |
| 29 | + ), |
| 30 | + ), |
| 31 | + ], |
| 32 | + ), |
| 33 | + ), |
| 34 | + ); |
| 35 | +
|
| 36 | + /// Wrap Ui item with animation & padding |
| 37 | + Widget _buildAnimatedItem( |
| 38 | + BuildContext context, |
| 39 | + int index, |
| 40 | + Animation<double> animation, |
| 41 | + ) => |
| 42 | + FadeTransition( |
| 43 | + opacity: Tween<double>( |
| 44 | + begin: 0, |
| 45 | + end: 1, |
| 46 | + ).animate(animation), |
| 47 | + child: SlideTransition( |
| 48 | + position: Tween<Offset>( |
| 49 | + begin: Offset(0, -0.1), |
| 50 | + end: Offset.zero, |
| 51 | + ).animate(animation), |
| 52 | + child: Padding( |
| 53 | + padding: EdgeInsets.only(right: 32), |
| 54 | + child: _buildCard(index.toString()), |
| 55 | + ), |
| 56 | + ), |
| 57 | + ); |
| 58 | +
|
| 59 | + /// UI item for showing |
| 60 | + Widget _buildCard(String text) => Builder( |
| 61 | + builder: (context) => Container( |
| 62 | + width: 140, |
| 63 | + child: ClipRRect( |
| 64 | + borderRadius: BorderRadius.circular(4), |
| 65 | + child: Material( |
| 66 | + color: Colors.lime, |
| 67 | + child: Center( |
| 68 | + child: Text( |
| 69 | + text, |
| 70 | + style: Theme.of(context) |
| 71 | + .textTheme |
| 72 | + .display1 |
| 73 | + .copyWith(color: Colors.black), |
| 74 | + ), |
| 75 | + ), |
| 76 | + ), |
| 77 | + ), |
| 78 | + ), |
| 79 | + ); |
| 80 | +} |
| 81 | +``` |
0 commit comments