-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_menu_screen.dart
More file actions
134 lines (124 loc) · 3.63 KB
/
main_menu_screen.dart
File metadata and controls
134 lines (124 loc) · 3.63 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import 'package:ant_new/style/my_button.dart';
import 'package:ant_new/style/palette.dart';
import 'package:ant_new/style/responsive_screen.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:just_audio/just_audio.dart';
class MainMenuScreen extends StatefulWidget {
const MainMenuScreen({super.key});
@override
State<MainMenuScreen> createState() => _MainMenuScreenState();
}
class _MainMenuScreenState extends State<MainMenuScreen> {
Palette palette = Palette();
static const _gap = SizedBox(height: 10);
AudioPlayer _audioPlayer = AudioPlayer();
@override
void initState() {
super.initState();
playMusic();
}
void playMusic() {
_audioPlayer = AudioPlayer();
_audioPlayer.setVolume(0.5);
_audioPlayer
.setAudioSource(AudioSource.asset(
'assets/audio/100 Heartbound OST Meandering Shadows.mp3'))
// ignore: body_might_complete_normally_catch_error
.catchError((error) {
debugPrint("Error in audio main_menu_screen $error");
});
_audioPlayer.play();
}
void play() {
_audioPlayer.play();
}
void pause() {
_audioPlayer.pause();
}
Widget _playerButton(PlayerState playerState) {
final processingState = playerState.processingState;
if (_audioPlayer.playing != true) {
return IconButton(
icon: const Icon(Icons.volume_off),
iconSize: 30.0,
onPressed: _audioPlayer.play,
);
} else if (processingState != ProcessingState.completed) {
return IconButton(
icon: const Icon(Icons.volume_up),
iconSize: 30.0,
onPressed: _audioPlayer.pause,
);
} else {
_audioPlayer.seek(Duration.zero);
_audioPlayer.play();
return IconButton(
icon: const Icon(Icons.replay),
iconSize: 30.0,
onPressed: () => _audioPlayer.seek(Duration.zero),
);
}
}
@override
void dispose() {
_audioPlayer.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: palette.backgroundMain,
body: ResponsiveScreen(
squarishMainArea: Center(
child: Transform.rotate(
angle: -0.1,
child: const Text(
'Ant Quest',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Permanent Marker',
fontSize: 75,
height: 1,
),
),
),
),
rectangularMenuArea: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyButton(
onPressed: () {
GoRouter.of(context).push('/play');
},
child: const Text('Play'),
),
_gap,
MyButton(
onPressed: () => GoRouter.of(context).push('/store'),
child: const Text('store'),
),
_gap,
MyButton(
onPressed: () => GoRouter.of(context).push('/settings'),
child: const Text('Settings'),
),
Center(
child: StreamBuilder<PlayerState>(
stream: _audioPlayer.playerStateStream,
builder: (context, snapshot) {
final playerState = snapshot.data;
return _playerButton(playerState!);
},
),
),
const Text(
"\"Music by Pirate Software\"",
style: TextStyle(fontSize: 10, fontWeight: FontWeight.bold),
)
],
),
),
);
}
}