Line data Source code
1 : import 'package:amadeus_proto/exercises/providers/beats_clicking_provider.dart';
2 : import 'package:flutter/material.dart';
3 : import 'package:provider/provider.dart';
4 :
5 : class AnimatedBar extends StatefulWidget {
6 0 : const AnimatedBar({super.key, required this.constraints});
7 :
8 : final BoxConstraints constraints;
9 :
10 0 : @override
11 0 : State<AnimatedBar> createState() => _AnimatedBarState();
12 : }
13 :
14 : class _AnimatedBarState extends State<AnimatedBar> {
15 : late final BeatsClickingProvider rhythmProvider;
16 :
17 : bool selected = false;
18 0 : @override
19 : void initState() {
20 0 : rhythmProvider = context.read<BeatsClickingProvider>();
21 0 : super.initState();
22 : }
23 :
24 0 : @override
25 : Widget build(BuildContext context) {
26 0 : return GestureDetector(
27 0 : onTap: () {
28 0 : rhythmProvider.startMilliseconds =
29 0 : DateTime.now().millisecondsSinceEpoch;
30 0 : rhythmProvider.playing = RhythmState.playing;
31 0 : Future.delayed(const Duration(milliseconds: 4500), () {
32 0 : rhythmProvider.playing = RhythmState.end;
33 : });
34 : },
35 0 : child: Center(
36 0 : child: Container(
37 0 : width: widget.constraints.maxWidth,
38 0 : height: widget.constraints.maxHeight,
39 : color: Colors.transparent,
40 0 : child: AnimatedAlign(
41 0 : alignment: (rhythmProvider.playing != RhythmState.start)
42 : ? Alignment.centerRight
43 : : Alignment.centerLeft,
44 0 : duration: (rhythmProvider.playing == RhythmState.playing)
45 : ? const Duration(milliseconds: 4500)
46 : : const Duration(milliseconds: 0),
47 : curve: Curves.linear,
48 0 : child: Container(
49 : color: Colors.red,
50 0 : width: widget.constraints.maxWidth * 0.007,
51 0 : height: widget.constraints.maxHeight * 0.3,
52 : ),
53 : ),
54 : ),
55 : ),
56 : );
57 : }
58 : }
|