|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +/// Flutter code sample for [AnimatedIcon]. |
| 6 | +
|
| 7 | +import 'package:flutter/material.dart'; |
| 8 | + |
| 9 | +final Map<String, AnimatedIconData> iconsList = <String, AnimatedIconData>{ |
| 10 | + 'add_event': AnimatedIcons.add_event, |
| 11 | + 'arrow_menu': AnimatedIcons.arrow_menu, |
| 12 | + 'close_menu': AnimatedIcons.close_menu, |
| 13 | + 'ellipsis_search': AnimatedIcons.ellipsis_search, |
| 14 | + 'event_add': AnimatedIcons.event_add, |
| 15 | + 'home_menu': AnimatedIcons.home_menu, |
| 16 | + 'list_view': AnimatedIcons.list_view, |
| 17 | + 'menu_arrow': AnimatedIcons.menu_arrow, |
| 18 | + 'menu_close': AnimatedIcons.menu_close, |
| 19 | + 'menu_home': AnimatedIcons.menu_home, |
| 20 | + 'pause_play': AnimatedIcons.pause_play, |
| 21 | + 'play_pause': AnimatedIcons.play_pause, |
| 22 | + 'search_ellipsis': AnimatedIcons.search_ellipsis, |
| 23 | + 'view_list': AnimatedIcons.view_list, |
| 24 | +}; |
| 25 | + |
| 26 | +void main() { |
| 27 | + runApp(const AnimatedIconApp()); |
| 28 | +} |
| 29 | + |
| 30 | +class AnimatedIconApp extends StatelessWidget { |
| 31 | + const AnimatedIconApp({super.key}); |
| 32 | + |
| 33 | + @override |
| 34 | + Widget build(BuildContext context) { |
| 35 | + return MaterialApp( |
| 36 | + theme: ThemeData( |
| 37 | + colorSchemeSeed: const Color(0xff6750a4), |
| 38 | + useMaterial3: true, |
| 39 | + ), |
| 40 | + home: const Scaffold( |
| 41 | + body: AnimatedIconExample(), |
| 42 | + ), |
| 43 | + ); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +class AnimatedIconExample extends StatefulWidget { |
| 48 | + const AnimatedIconExample({super.key}); |
| 49 | + |
| 50 | + @override |
| 51 | + State<AnimatedIconExample> createState() => _AnimatedIconExampleState(); |
| 52 | +} |
| 53 | + |
| 54 | +class _AnimatedIconExampleState extends State<AnimatedIconExample> with SingleTickerProviderStateMixin { |
| 55 | + late AnimationController controller; |
| 56 | + late Animation<double> animation; |
| 57 | + |
| 58 | + @override |
| 59 | + void initState() { |
| 60 | + super.initState(); |
| 61 | + controller = AnimationController( |
| 62 | + vsync: this, |
| 63 | + duration: const Duration(seconds: 2), |
| 64 | + )..forward() |
| 65 | + ..repeat(reverse: true); |
| 66 | + animation = Tween<double>(begin: 0.0, end: 1.0).animate(controller); |
| 67 | + } |
| 68 | + |
| 69 | + @override |
| 70 | + void dispose() { |
| 71 | + controller.dispose(); |
| 72 | + super.dispose(); |
| 73 | + } |
| 74 | + |
| 75 | + @override |
| 76 | + Widget build(BuildContext context) { |
| 77 | + return Scaffold( |
| 78 | + body: GridView( |
| 79 | + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( |
| 80 | + crossAxisCount: 4, |
| 81 | + ), |
| 82 | + children: iconsList.entries.map((MapEntry<String, AnimatedIconData> entry) { |
| 83 | + return Card( |
| 84 | + child: Center( |
| 85 | + child: Column( |
| 86 | + mainAxisAlignment: MainAxisAlignment.center, |
| 87 | + children: <Widget>[ |
| 88 | + AnimatedIcon( |
| 89 | + icon: entry.value, |
| 90 | + progress: animation, |
| 91 | + size: 72.0, |
| 92 | + semanticLabel: entry.key, |
| 93 | + ), |
| 94 | + const SizedBox(height: 8.0), |
| 95 | + Text(entry.key), |
| 96 | + ], |
| 97 | + ), |
| 98 | + ), |
| 99 | + ); |
| 100 | + }).toList(), |
| 101 | + ), |
| 102 | + ); |
| 103 | + } |
| 104 | +} |
0 commit comments