Skip to content

Instantly share code, notes, and snippets.

@peagha
Created July 6, 2020 23:04
Show Gist options
  • Save peagha/c5a9d08d5fc64397e7624103d3b38acc to your computer and use it in GitHub Desktop.
Save peagha/c5a9d08d5fc64397e7624103d3b38acc to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('AnimatedContainer Demo'),
),
body: Center(child: Highlight(child: Text('123123123122312312'))),
)));
class Highlight extends StatefulWidget {
Highlight({this.child});
final Widget child;
@override
_HighlightState createState() => _HighlightState(child: child);
}
class _HighlightState extends State<Highlight> {
_HighlightState({this.child});
Color _color = Colors.green;
final Widget child;
@override
void initState() {
super.initState();
Timer(
const Duration(seconds: 3),
() => setState(
() {
_color = null;
},
),
);
}
@override
Widget build(BuildContext context) {
return AnimatedContainer(
child: FlatButton(child: child, onPressed: () {}),
// Use the properties stored in the State class.
decoration: BoxDecoration(
color: _color,
),
// Define how long the animation should take.
duration: Duration(seconds: 1),
// Provide an optional curve to make the animation feel smoother.
curve: Curves.fastOutSlowIn,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment