Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:flutter/material.dart'; |
| 6 | |
| 7 | class AnimatedIconsTestApp extends StatelessWidget { |
Michael Goderbauer | ca2d60e | 2022-03-30 14:05:05 -0700 | [diff] [blame] | 8 | const AnimatedIconsTestApp({super.key}); |
Michael Goderbauer | 0f56829 | 2021-03-02 10:14:02 -0800 | [diff] [blame] | 9 | |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 10 | @override |
| 11 | Widget build(BuildContext context) { |
Dan Field | ea5435c | 2018-09-25 13:57:12 -0400 | [diff] [blame] | 12 | return const MaterialApp( |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 13 | title: 'Animated Icons Test', |
Dan Field | ea5435c | 2018-09-25 13:57:12 -0400 | [diff] [blame] | 14 | home: Scaffold( |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 15 | body: IconsList(), |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 16 | ), |
| 17 | ); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | class IconsList extends StatelessWidget { |
Michael Goderbauer | ca2d60e | 2022-03-30 14:05:05 -0700 | [diff] [blame] | 22 | const IconsList({super.key}); |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 23 | |
| 24 | @override |
| 25 | Widget build(BuildContext context) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 26 | return ListView( |
Alexandre Ardhuin | f62afdc | 2018-10-01 21:29:08 +0200 | [diff] [blame] | 27 | children: samples.map<IconSampleRow>((IconSample s) => IconSampleRow(s)).toList(), |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 28 | ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | class IconSampleRow extends StatefulWidget { |
Michael Goderbauer | ca2d60e | 2022-03-30 14:05:05 -0700 | [diff] [blame] | 33 | const IconSampleRow(this.sample, {super.key}); |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 34 | |
| 35 | final IconSample sample; |
| 36 | |
| 37 | @override |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 38 | State createState() => IconSampleRowState(); |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin { |
Abhishek Ghaskata | a8e2606 | 2021-05-27 23:19:02 +0530 | [diff] [blame] | 42 | late final AnimationController progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300)); |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 43 | |
| 44 | @override |
| 45 | Widget build(BuildContext context) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 46 | return ListTile( |
| 47 | leading: InkWell( |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 48 | onTap: () { progress.forward(from: 0.0); }, |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 49 | child: AnimatedIcon( |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 50 | icon: widget.sample.icon, |
| 51 | progress: progress, |
| 52 | color: Colors.lightBlue, |
| 53 | ), |
| 54 | ), |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 55 | title: Text(widget.sample.description), |
| 56 | subtitle: Slider( |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 57 | value: progress.value, |
Alexander Aprelev | 2f8474f | 2018-03-12 15:44:25 -0700 | [diff] [blame] | 58 | onChanged: (double v) { progress.animateTo(v, duration: Duration.zero); }, |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 59 | ), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | @override |
| 64 | void initState() { |
| 65 | super.initState(); |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 66 | progress.addListener(_handleChange); |
| 67 | } |
| 68 | |
| 69 | @override |
| 70 | void dispose() { |
| 71 | progress.removeListener(_handleChange); |
| 72 | super.dispose(); |
| 73 | } |
| 74 | |
| 75 | void _handleChange() { |
| 76 | setState(() {}); |
| 77 | } |
| 78 | } |
| 79 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 80 | const List<IconSample> samples = <IconSample> [ |
| 81 | IconSample(AnimatedIcons.arrow_menu, 'arrow_menu'), |
| 82 | IconSample(AnimatedIcons.menu_arrow, 'menu_arrow'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 83 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 84 | IconSample(AnimatedIcons.close_menu, 'close_menu'), |
| 85 | IconSample(AnimatedIcons.menu_close, 'menu_close'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 86 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 87 | IconSample(AnimatedIcons.home_menu, 'home_menu'), |
| 88 | IconSample(AnimatedIcons.menu_home, 'menu_home'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 89 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 90 | IconSample(AnimatedIcons.play_pause, 'play_pause'), |
| 91 | IconSample(AnimatedIcons.pause_play, 'pause_play'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 92 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 93 | IconSample(AnimatedIcons.list_view, 'list_view'), |
| 94 | IconSample(AnimatedIcons.view_list, 'view_list'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 95 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 96 | IconSample(AnimatedIcons.add_event, 'add_event'), |
| 97 | IconSample(AnimatedIcons.event_add, 'event_add'), |
amirh | 85b5b88 | 2018-01-29 10:36:59 -0800 | [diff] [blame] | 98 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 99 | IconSample(AnimatedIcons.ellipsis_search, 'ellipsis_search'), |
| 100 | IconSample(AnimatedIcons.search_ellipsis, 'search_ellipsis'), |
amirh | 492e311 | 2018-01-29 09:19:53 -0800 | [diff] [blame] | 101 | ]; |
| 102 | |
| 103 | class IconSample { |
| 104 | const IconSample(this.icon, this.description); |
| 105 | final AnimatedIconData icon; |
| 106 | final String description; |
| 107 | } |
| 108 | |
Michael Goderbauer | 0f56829 | 2021-03-02 10:14:02 -0800 | [diff] [blame] | 109 | void main() => runApp(const AnimatedIconsTestApp()); |