-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
78 lines (69 loc) · 1.95 KB
/
main.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
import 'package:flutter/material.dart';
import 'package:flutter_minimalist_audio_player/flutter_minimalist_audio_player.dart';
const radios = {
"Europe 2": "https://europe2.lmn.fm/europe2.mp3",
"RTS": "https://sc.creacast.com/rts-national.mp3",
"Skyrock": "https://icecast8.play.cz/skyrock128.mp3",
};
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
MiniPlayer? _currentPlayer;
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('MinimalistAudioPlayer'),
),
body: Center(
child: ListView.builder(
shrinkWrap: true,
itemCount: radios.length,
itemExtent: 50,
itemBuilder: (context, index) {
return DefaultTextStyle(
style: const TextStyle().copyWith(fontSize: 25, color: Colors.amber),
child: radioWidget(radios.keys.elementAt(index), radios.values.elementAt(index)));
},
),
),
),
);
}
Widget radioWidget(String name, String url) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.radio,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(width: 5),
Text(name),
const SizedBox(width: 5),
MinimalistAudioPlayer(
media: url,
beforeStart: (p) async {
await _currentPlayer?.fadeOut();
_currentPlayer = p;
},
onStop: (p) {
if (_currentPlayer == p) _currentPlayer = null;
},
),
],
);
}
}