Last active
October 25, 2019 17:43
-
-
Save legalcodes/8501583cb789504d75317a5ba1ca6930 to your computer and use it in GitHub Desktop.
Vanilla Animated Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright 2019 the Dart project 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 'dart:math'; | |
| import 'package:flutter_web/material.dart'; | |
| import 'package:flutter_web_test/flutter_web_test.dart'; | |
| import 'package:flutter_web_ui/ui.dart' as ui; | |
| double randomBorderRadius() { | |
| return Random().nextDouble() * 64; | |
| } | |
| double randomMargin() { | |
| return Random().nextDouble() * 64; | |
| } | |
| Color randomColor() { | |
| return Color(0xFFFFFFFF & Random().nextInt(0xFFFFFFFF)); | |
| } | |
| class AnimatedContainerDemo extends StatefulWidget { | |
| _AnimatedContainerDemoState createState() => _AnimatedContainerDemoState(); | |
| } | |
| class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> { | |
| Color color; | |
| double borderRadius; | |
| double margin; | |
| @override | |
| initState() { | |
| color = randomColor(); | |
| borderRadius = randomBorderRadius(); | |
| margin = randomMargin(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Center( | |
| child: Column( | |
| children: <Widget>[ | |
| SizedBox( | |
| width: 128, | |
| height: 128, | |
| child: Container( | |
| margin: EdgeInsets.all(margin), | |
| decoration: BoxDecoration( | |
| color: color, | |
| borderRadius: BorderRadius.circular(borderRadius), | |
| ), | |
| ), | |
| ), | |
| MaterialButton( | |
| color: Theme.of(context).primaryColor, | |
| child: Text( | |
| 'change', | |
| style: TextStyle(color: Colors.white), | |
| ), | |
| onPressed: () => null, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: AnimatedContainerDemo(), | |
| ); | |
| } | |
| } | |
| Future<void> main() async { | |
| await ui.webOnlyInitializePlatform(); | |
| runApp( | |
| MyApp(), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment