animated_icons.dart 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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 {
  @override
  Widget build(BuildContext context) {
10
    return const MaterialApp(
11
      title: 'Animated Icons Test',
12
      home: Scaffold(
13
        body: IconsList(),
14 15 16 17 18 19 20 21 22 23
      ),
    );
  }
}

class IconsList extends StatelessWidget {
  const IconsList();

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

class IconSampleRow extends StatefulWidget {
  const IconSampleRow(this.sample);

  final IconSample sample;

  @override
36
  State createState() => IconSampleRowState();
37 38 39 40 41 42 43
}

class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin {
  AnimationController progress;

  @override
  Widget build(BuildContext context) {
44 45
    return ListTile(
      leading: InkWell(
46
        onTap: () { progress.forward(from: 0.0); },
47
        child: AnimatedIcon(
48 49 50 51 52
          icon: widget.sample.icon,
          progress: progress,
          color: Colors.lightBlue,
        ),
      ),
53 54
      title: Text(widget.sample.description),
      subtitle: Slider(
55
        value: progress.value,
56
        onChanged: (double v) { progress.animateTo(v, duration: Duration.zero); },
57 58 59 60 61 62 63
      ),
    );
  }

  @override
  void initState() {
    super.initState();
64
    progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
65 66 67 68 69 70 71 72 73 74 75 76 77 78
    progress.addListener(_handleChange);
  }

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

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

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

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

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

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

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

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

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

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

108
void main() => runApp(AnimatedIconsTestApp());