-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy path01_animated_container.dart
More file actions
83 lines (74 loc) · 2.49 KB
/
01_animated_container.dart
File metadata and controls
83 lines (74 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'package:flutter/material.dart';
double generateBorderRadius() => Random().nextDouble() * 64;
double generateMargin() => Random().nextDouble() * 64;
Color generateColor() => Color(0xFFFFFFFF & Random().nextInt(0xFFFFFFFF));
class AnimatedContainerDemo extends StatefulWidget {
static String routeName = '/basics/01_animated_container';
@override
_AnimatedContainerDemoState createState() => _AnimatedContainerDemoState();
}
class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> {
Color color;
double borderRadius;
double margin;
@override
void initState() {
super.initState();
color = Colors.deepPurple;
borderRadius = generateBorderRadius();
margin = generateMargin();
}
void change() {
setState(() {
color = generateColor();
borderRadius = generateBorderRadius();
margin = generateMargin();
});
}
@override
Widget build(BuildContext context) {
// This widget is built using an AnimatedContainer, one of the easiest to use
// animated Widgets. Whenever the AnimatedContainer's properties, such as decoration,
// change, it will handle animating from the previous value to the new value. You can
// specify both a Duration and a Curve for the animation.
// This Widget is useful for designing animated interfaces that just need to change
// the properties of a container. For example, you could use this to design expanding
// and shrinking cards.
return Scaffold(
appBar: AppBar(
title: Text('AnimatedContainer'),
),
body: Center(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(8.0),
child: SizedBox(
width: 128,
height: 128,
child: AnimatedContainer(
margin: EdgeInsets.all(margin),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(borderRadius),
),
duration: const Duration(milliseconds: 400),
),
),
),
RaisedButton(
child: Text(
'change',
),
onPressed: () => change(),
),
],
),
),
);
}
}