animated_icons.dart 2.84 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

class AnimatedIconsTestApp extends StatelessWidget {
8
  const AnimatedIconsTestApp({super.key});
9

10 11
  @override
  Widget build(BuildContext context) {
12
    return const MaterialApp(
13
      title: 'Animated Icons Test',
14
      home: Scaffold(
15
        body: IconsList(),
16 17 18 19 20 21
      ),
    );
  }
}

class IconsList extends StatelessWidget {
22
  const IconsList({super.key});
23 24 25

  @override
  Widget build(BuildContext context) {
26
    return ListView(
27
      children: samples.map<IconSampleRow>((IconSample s) => IconSampleRow(s)).toList(),
28 29 30 31 32
    );
  }
}

class IconSampleRow extends StatefulWidget {
33
  const IconSampleRow(this.sample, {super.key});
34 35 36 37

  final IconSample sample;

  @override
38
  State createState() => IconSampleRowState();
39 40 41
}

class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin {
42
  late final AnimationController progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
43 44 45

  @override
  Widget build(BuildContext context) {
46 47
    return ListTile(
      leading: InkWell(
48
        onTap: () { progress.forward(from: 0.0); },
49
        child: AnimatedIcon(
50 51 52 53 54
          icon: widget.sample.icon,
          progress: progress,
          color: Colors.lightBlue,
        ),
      ),
55 56
      title: Text(widget.sample.description),
      subtitle: Slider(
57
        value: progress.value,
58
        onChanged: (double v) { progress.animateTo(v, duration: Duration.zero); },
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    progress.addListener(_handleChange);
  }

  @override
  void dispose() {
    progress.removeListener(_handleChange);
    super.dispose();
  }

  void _handleChange() {
    setState(() {});
  }
}

80 81 82
const List<IconSample> samples = <IconSample> [
  IconSample(AnimatedIcons.arrow_menu, 'arrow_menu'),
  IconSample(AnimatedIcons.menu_arrow, 'menu_arrow'),
83

84 85
  IconSample(AnimatedIcons.close_menu, 'close_menu'),
  IconSample(AnimatedIcons.menu_close, 'menu_close'),
86

87 88
  IconSample(AnimatedIcons.home_menu, 'home_menu'),
  IconSample(AnimatedIcons.menu_home, 'menu_home'),
89

90 91
  IconSample(AnimatedIcons.play_pause, 'play_pause'),
  IconSample(AnimatedIcons.pause_play, 'pause_play'),
92

93 94
  IconSample(AnimatedIcons.list_view, 'list_view'),
  IconSample(AnimatedIcons.view_list, 'view_list'),
95

96 97
  IconSample(AnimatedIcons.add_event, 'add_event'),
  IconSample(AnimatedIcons.event_add, 'event_add'),
98

99 100
  IconSample(AnimatedIcons.ellipsis_search, 'ellipsis_search'),
  IconSample(AnimatedIcons.search_ellipsis, 'search_ellipsis'),
101 102 103 104 105 106 107 108
];

class IconSample {
  const IconSample(this.icon, this.description);
  final AnimatedIconData icon;
  final String description;
}

109
void main() => runApp(const AnimatedIconsTestApp());