Skip to content

Instantly share code, notes, and snippets.

@divyanshub024
Last active June 22, 2023 06:35
Show Gist options
  • Select an option

  • Save divyanshub024/b25b3c627d1d039e00896ab81b2485d5 to your computer and use it in GitHub Desktop.

Select an option

Save divyanshub024/b25b3c627d1d039e00896ab81b2485d5 to your computer and use it in GitHub Desktop.
Flutter Animation I: Background Color Transition
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Background color transition',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 10),
vsync: this,
)..repeat();
}
Animatable<Color> background = TweenSequence<Color>([
TweenSequenceItem(
weight: 1.0,
tween: ColorTween(
begin: Colors.red,
end: Colors.green,
),
),
TweenSequenceItem(
weight: 1.0,
tween: ColorTween(
begin: Colors.green,
end: Colors.blue,
),
),
TweenSequenceItem(
weight: 1.0,
tween: ColorTween(
begin: Colors.blue,
end: Colors.pink,
),
),
]);
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Scaffold(
body: Container(
color: background
.evaluate(AlwaysStoppedAnimation(_controller.value)),
),
);
});
}
}
@Pritom-Chaki
Copy link
Copy Markdown

This code is not working recent flutter version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment