progress_indicator.dart 3.09 KB
Newer Older
1 2 3 4
// Copyright 2015 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
import 'package:sky/animation.dart';
6 7
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
8 9 10

class ProgressIndicatorApp extends App {

Eric Seidel's avatar
Eric Seidel committed
11
  ValueAnimation<double> valueAnimation;
12 13 14 15
  Direction valueAnimationDirection = Direction.forward;

  void initState() {
    super.initState();
Eric Seidel's avatar
Eric Seidel committed
16
    valueAnimation = new ValueAnimation<double>()
17 18 19 20 21 22 23 24 25 26
      ..duration = const Duration(milliseconds: 1500)
      ..variable = new AnimatedValue<double>(
        0.0,
        end: 1.0,
        curve: ease,
        reverseCurve: ease,
        interval: new Interval(0.0, 0.9)
      );
  }

27
  void handleTap() {
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    if (valueAnimation.isAnimating)
      valueAnimation.stop();
    else
      valueAnimation.resume();
  }

  void reverseValueAnimationDirection() {
    setState(() {
      valueAnimationDirection = (valueAnimationDirection == Direction.forward)
        ? Direction.reverse
        : Direction.forward;
    });
  }

  Widget buildIndicators() {
    List<Widget> indicators = <Widget>[
        new SizedBox(
          width: 200.0,
          child: new LinearProgressIndicator()
        ),
        new LinearProgressIndicator(),
        new LinearProgressIndicator(),
Eric Seidel's avatar
Eric Seidel committed
50
        new LinearProgressIndicator(value: valueAnimation.value),
51 52 53 54
        new CircularProgressIndicator(),
        new SizedBox(
            width: 20.0,
            height: 20.0,
Eric Seidel's avatar
Eric Seidel committed
55
            child: new CircularProgressIndicator(value: valueAnimation.value)
56 57 58 59
        ),
        new SizedBox(
          width: 50.0,
          height: 30.0,
Eric Seidel's avatar
Eric Seidel committed
60
          child: new CircularProgressIndicator(value: valueAnimation.value)
61 62
        )
    ];
63
    return new Column(
64 65 66 67 68 69 70 71
      indicators
        .map((c) => new Container(child: c, margin: const EdgeDims.symmetric(vertical: 20.0)))
        .toList(),
      justifyContent: FlexJustifyContent.center
    );
  }

  Widget build() {
72 73
    Widget body = new GestureDetector(
      onTap: handleTap,
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
      child: new Container(
        padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
        decoration: new BoxDecoration(backgroundColor: Theme.of(this).cardColor),
        child: new BuilderTransition(
          variables: [valueAnimation.variable],
          direction: valueAnimationDirection,
          performance: valueAnimation,
          onDismissed: reverseValueAnimationDirection,
          onCompleted: reverseValueAnimationDirection,
          builder: buildIndicators
        )
      )
    );

    return new IconTheme(
      data: const IconThemeData(color: IconThemeColor.white),
      child: new Theme(
        data: new ThemeData(
          brightness: ThemeBrightness.light,
93 94
          primarySwatch: colors.Blue,
          accentColor: colors.RedAccent[200]
95
        ),
96 97
        child: new Title(
          title: 'Cards',
98 99 100 101 102 103 104 105 106 107 108 109 110
          child: new Scaffold(
            toolbar: new ToolBar(center: new Text('Progress Indicators')),
            body: body
          )
        )
      )
    );
  }
}

void main() {
  runApp(new ProgressIndicatorApp());
}