-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatedmodalbarrier.dart
79 lines (73 loc) · 2.38 KB
/
animatedmodalbarrier.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
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
import 'package:flutter/material.dart';
class AnimatedModalBarrierWidget extends StatefulWidget {
const AnimatedModalBarrierWidget({super.key});
@override
State<AnimatedModalBarrierWidget> createState() =>
_AnimatedModalBarrierWidgetState();
}
class _AnimatedModalBarrierWidgetState extends State<AnimatedModalBarrierWidget>
with SingleTickerProviderStateMixin {
bool _isPressed = false;
late Widget _animatedModelBarrier;
late AnimationController _controller;
late Animation<Color?> _colorAnimation;
@override
void initState() {
ColorTween colorTween = ColorTween(
begin: Colors.orange.withOpacity(0.5),
end: Colors.blueGrey.withOpacity(0.5));
_controller =
AnimationController(vsync: this, duration: const Duration(seconds: 3));
_colorAnimation = colorTween.animate(_controller);
_animatedModelBarrier = AnimatedModalBarrier(
color: _colorAnimation,
dismissible: true,
);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("AnimatedModalbarrier"),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 250,
height: 100,
child: Stack(
alignment: AlignmentDirectional.center,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orangeAccent),
onPressed: () {
setState(() {
_isPressed = true;
});
_controller.reset();
_controller.forward();
Future.delayed(const Duration(seconds: 3), (() {
setState(() {
_isPressed = false;
});
}));
},
child: const Text('Press'),
),
if (_isPressed) _animatedModelBarrier
],
),
)
],
),
),
),
);
}
}