Snapshot of Radio UI这是我的电台播放器应用的代码。它由两个收音机组成。即Radio1(已提供源代码)和Radio2。应用程序由底部导航栏组成,其中包含Home,Radio1,Radio2等,如快照所示。我面临的主要问题是:
Radio1.dart的源代码:
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
class Radio1 extends StatefulWidget {
@override
_Radio1State createState() => _Radio1State();
}
class _Radio1State extends State<Radio1> {
AudioPlayer audioPlayer = new AudioPlayer();
bool _isPlaying = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: Column(
children: <Widget>[ //new
SizedBox(
height: 50,
),
//Icon(
// Icons.arrow_drop_down,
//size: 40,
//),
//new
Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 50),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Color(0x46000000),
offset: Offset(0, 20),
spreadRadius: 0,
blurRadius: 30,
),
BoxShadow(
color: Color(0x11000000),
offset: Offset(0, 10),
spreadRadius: 0,
blurRadius: 30,
),
],
),
//new
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image(
image: NetworkImage(
"https://www.sansar.com/wp-content/uploads/2019/07/photo.jpg"),
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.width * 0.7,
fit: BoxFit.cover,
),
),
),
Text(
"Dj Jay",
style: TextStyle(fontSize: 30, fontWeight: FontWeight.w500),
),
Text(
"(The trance house)",
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
),
/* Slider(
value: 10,
onChanged: (v) {},
max: 170,
min: 0,
activeColor: Color(0xFF5E35B1),
), */
Text(
"If you are unable to listen to the audio, please try updating app.",
style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
),
GestureDetector(
onTap: () {
getAudio();
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
_isPlaying == false
? Icons.play_circle_outline
: Icons.pause_circle_outline,
size: 60.0,
),
],
),
)
],
),
),
),
);
}
void getAudio() async {
var url = "https://stream.zenolive.com/nmgn8vdepv5tv.aac";
if (_isPlaying) {
var res = await audioPlayer.pause();
if (res == 1) {
setState(() {
_isPlaying = false;
});
}
} else {
var res = await audioPlayer.play(url, isLocal: true);
if (res == 1) {
setState(() {
_isPlaying = true;
});
}
}
}
}