blob: daa3f572c0023711c8a9bc67715d98ed7f8248ed [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
amirh492e3112018-01-29 09:19:53 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7class AnimatedIconsTestApp extends StatelessWidget {
Michael Goderbauerca2d60e2022-03-30 14:05:05 -07008 const AnimatedIconsTestApp({super.key});
Michael Goderbauer0f568292021-03-02 10:14:02 -08009
amirh492e3112018-01-29 09:19:53 -080010 @override
11 Widget build(BuildContext context) {
Dan Fieldea5435c2018-09-25 13:57:12 -040012 return const MaterialApp(
amirh492e3112018-01-29 09:19:53 -080013 title: 'Animated Icons Test',
Dan Fieldea5435c2018-09-25 13:57:12 -040014 home: Scaffold(
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020015 body: IconsList(),
amirh492e3112018-01-29 09:19:53 -080016 ),
17 );
18 }
19}
20
21class IconsList extends StatelessWidget {
Michael Goderbauerca2d60e2022-03-30 14:05:05 -070022 const IconsList({super.key});
amirh492e3112018-01-29 09:19:53 -080023
24 @override
25 Widget build(BuildContext context) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020026 return ListView(
Alexandre Ardhuinf62afdc2018-10-01 21:29:08 +020027 children: samples.map<IconSampleRow>((IconSample s) => IconSampleRow(s)).toList(),
amirh492e3112018-01-29 09:19:53 -080028 );
29 }
30}
31
32class IconSampleRow extends StatefulWidget {
Michael Goderbauerca2d60e2022-03-30 14:05:05 -070033 const IconSampleRow(this.sample, {super.key});
amirh492e3112018-01-29 09:19:53 -080034
35 final IconSample sample;
36
37 @override
Alexandre Ardhuind927c932018-09-12 08:29:29 +020038 State createState() => IconSampleRowState();
amirh492e3112018-01-29 09:19:53 -080039}
40
41class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin {
Abhishek Ghaskataa8e26062021-05-27 23:19:02 +053042 late final AnimationController progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
amirh492e3112018-01-29 09:19:53 -080043
44 @override
45 Widget build(BuildContext context) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020046 return ListTile(
47 leading: InkWell(
amirh492e3112018-01-29 09:19:53 -080048 onTap: () { progress.forward(from: 0.0); },
Alexandre Ardhuind927c932018-09-12 08:29:29 +020049 child: AnimatedIcon(
amirh492e3112018-01-29 09:19:53 -080050 icon: widget.sample.icon,
51 progress: progress,
52 color: Colors.lightBlue,
53 ),
54 ),
Alexandre Ardhuind927c932018-09-12 08:29:29 +020055 title: Text(widget.sample.description),
56 subtitle: Slider(
amirh492e3112018-01-29 09:19:53 -080057 value: progress.value,
Alexander Aprelev2f8474f2018-03-12 15:44:25 -070058 onChanged: (double v) { progress.animateTo(v, duration: Duration.zero); },
amirh492e3112018-01-29 09:19:53 -080059 ),
60 );
61 }
62
63 @override
64 void initState() {
65 super.initState();
amirh492e3112018-01-29 09:19:53 -080066 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 Ardhuineda03e22018-08-02 12:02:32 +020080const List<IconSample> samples = <IconSample> [
81 IconSample(AnimatedIcons.arrow_menu, 'arrow_menu'),
82 IconSample(AnimatedIcons.menu_arrow, 'menu_arrow'),
amirh85b5b882018-01-29 10:36:59 -080083
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020084 IconSample(AnimatedIcons.close_menu, 'close_menu'),
85 IconSample(AnimatedIcons.menu_close, 'menu_close'),
amirh85b5b882018-01-29 10:36:59 -080086
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020087 IconSample(AnimatedIcons.home_menu, 'home_menu'),
88 IconSample(AnimatedIcons.menu_home, 'menu_home'),
amirh85b5b882018-01-29 10:36:59 -080089
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020090 IconSample(AnimatedIcons.play_pause, 'play_pause'),
91 IconSample(AnimatedIcons.pause_play, 'pause_play'),
amirh85b5b882018-01-29 10:36:59 -080092
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020093 IconSample(AnimatedIcons.list_view, 'list_view'),
94 IconSample(AnimatedIcons.view_list, 'view_list'),
amirh85b5b882018-01-29 10:36:59 -080095
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020096 IconSample(AnimatedIcons.add_event, 'add_event'),
97 IconSample(AnimatedIcons.event_add, 'event_add'),
amirh85b5b882018-01-29 10:36:59 -080098
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020099 IconSample(AnimatedIcons.ellipsis_search, 'ellipsis_search'),
100 IconSample(AnimatedIcons.search_ellipsis, 'search_ellipsis'),
amirh492e3112018-01-29 09:19:53 -0800101];
102
103class IconSample {
104 const IconSample(this.icon, this.description);
105 final AnimatedIconData icon;
106 final String description;
107}
108
Michael Goderbauer0f568292021-03-02 10:14:02 -0800109void main() => runApp(const AnimatedIconsTestApp());