-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatedcrossfade.dart
50 lines (46 loc) · 1.3 KB
/
animatedcrossfade.dart
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
import 'package:flutter/material.dart';
class AnimatedCrossFadeWidget extends StatefulWidget {
const AnimatedCrossFadeWidget({super.key});
@override
State<AnimatedCrossFadeWidget> createState() =>
_AnimatedCrossFadeWidgetState();
}
class _AnimatedCrossFadeWidgetState extends State<AnimatedCrossFadeWidget> {
bool _bool = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Animation Cross Fade'),
),
body: Column(
children: [
const SizedBox(
width: double.infinity,
height: 100,
),
TextButton(
onPressed: () {
setState(() {
_bool = !_bool;
});
},
child: const Text('Switch'),
),
AnimatedCrossFade(
firstChild: Image.asset(
'assets/bg/asthetic_bg.jpg',
width: 150,
height: 400,
),
secondChild: Image.asset('assets/bg/asthetic_night_bg.jpg',
width: 150, height: 400),
crossFadeState:
_bool ? CrossFadeState.showFirst : CrossFadeState.showSecond,
duration: const Duration(seconds: 2),
),
],
),
);
}
}