animated_icons.dart 3.13 KB
Newer Older
1 2 3 4
// 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.

5 6 7
import 'dart:io';

import 'package:flutter/foundation.dart';
8 9 10 11 12
import 'package:flutter/material.dart';

class AnimatedIconsTestApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
13
    return const MaterialApp(
14
      title: 'Animated Icons Test',
15
      home: Scaffold(
16
        body: IconsList(),
17 18 19 20 21 22 23 24 25 26
      ),
    );
  }
}

class IconsList extends StatelessWidget {
  const IconsList();

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

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

  final IconSample sample;

  @override
39
  State createState() => IconSampleRowState();
40 41 42 43 44 45 46
}

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

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

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

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

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

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

86 87
  IconSample(AnimatedIcons.close_menu, 'close_menu'),
  IconSample(AnimatedIcons.menu_close, 'menu_close'),
88

89 90
  IconSample(AnimatedIcons.home_menu, 'home_menu'),
  IconSample(AnimatedIcons.menu_home, 'menu_home'),
91

92 93
  IconSample(AnimatedIcons.play_pause, 'play_pause'),
  IconSample(AnimatedIcons.pause_play, 'pause_play'),
94

95 96
  IconSample(AnimatedIcons.list_view, 'list_view'),
  IconSample(AnimatedIcons.view_list, 'view_list'),
97

98 99
  IconSample(AnimatedIcons.add_event, 'add_event'),
  IconSample(AnimatedIcons.event_add, 'event_add'),
100

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

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

111 112 113 114 115 116 117 118
void main() {
  if (Platform.isMacOS) {
    // TODO(gspencergoog): Update this when TargetPlatform includes macOS. https://github.com/flutter/flutter/issues/31366
    // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
    debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  }
  runApp(AnimatedIconsTestApp());
}