Files
GSFV2/gsf/lib/views/pages/podcast/podcast_list.dart
2024-04-22 23:50:28 -07:00

452 lines
15 KiB
Dart

// ignore_for_file: prefer_const_constructors
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../theme.dart';
class PodcastList extends StatefulWidget {
const PodcastList({Key? key}) : super(key: key);
@override
State<PodcastList> createState() => _PodcastListState();
}
class _PodcastListState extends State<PodcastList> with WidgetsBindingObserver {
bool isplaying = false;
bool playOrNot = false;
double value = 0;
List audioList = [
"https://pwdown.info/8555/01 Desi Kalakaar - Yo Yo Honey Singh (PagalWorld.com).mp3",
"https://pwdown.info/113504/First Kiss - Yo Yo Honey Singh.mp3"
];
String audioMusic =
"https://pwdown.info/113504/First Kiss - Yo Yo Honey Singh.mp3";
initplayer() async {
// await player.setSourceUrl(audioMusic);
await player.setSource(AssetSource("audio/nature.mp3"));
duration = await player.getDuration();
}
@override
void initState() {
super.initState();
initplayer();
checkMusicApp();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.paused) {
//stop your audio player
setState(() {
player.pause();
isplaying = false;
});
// dispose();
}
}
checkMusicApp() {
player.onPlayerComplete.listen((event) {
setState(() {
isplaying = false;
});
});
}
@override
void dispose() async {
await player.pause();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
// late AudioPlayer audioPlayer;
final player = AudioPlayer();
Duration? duration = Duration(seconds: 0);
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
setState(() {
player.stop();
isplaying = false;
});
return true;
},
child: Scaffold(
backgroundColor: ColorConstants.kBlack,
appBar: PreferredSize(
preferredSize: Size.fromHeight(300),
child: AppBar(
backgroundColor: Colors.transparent,
leadingWidth: 70,
flexibleSpace: FlexibleSpaceBar(
titlePadding: EdgeInsets.all(0),
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Set To Inspire',
style: TextStyle(
fontSize: 35,
color: ColorConstants.kWhite,
fontFamily: 'SFPRO',
height: 0,
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'Our Daily Latest Podcast',
style: TextStyle(
fontSize: 22,
fontFamily: 'SFPRO',
color: Color(0xffD9D9D9),
fontWeight: FontWeight.w600,
),
),
Spacer(),
Container(
width: 52,
height: 52,
decoration: BoxDecoration(
color:
ColorConstants.kPrimaryColor.withOpacity(0.9),
shape: BoxShape.circle,
),
child: const Icon(
Icons.play_arrow_rounded,
color: ColorConstants.kBlack,
size: 40,
),
),
],
),
],
),
),
background: Image.asset(
'assets/image/podcast/podcastImg.jpg',
fit: BoxFit.cover,
alignment: Alignment.topCenter,
),
),
leading: Padding(
padding: const EdgeInsets.only(
top: 10, left: 18, right: 15, bottom: 10),
child: InkWell(
splashColor: const Color(0xff313030).withOpacity(0.5),
borderRadius: BorderRadius.circular(7),
onTap: () {
Get.back();
// setState(() {
// player.pause();
// isplaying = false;
// });
dispose();
},
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: const Color(0xff313030),
borderRadius: BorderRadius.circular(7),
),
child: const Padding(
padding: EdgeInsets.only(left: 8.0),
child: Icon(
Icons.arrow_back_ios,
color: ColorConstants.kWhite,
size: 20,
),
),
),
),
),
),
),
body: SingleChildScrollView(
physics: ScrollPhysics(),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 20),
Text(
'Latest',
style: TextStyle(
fontSize: 22,
fontFamily: 'SFPRO',
color: ColorConstants.kWhite,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 30),
ListView.builder(
scrollDirection: Axis.vertical,
itemCount: 8,
shrinkWrap: true,
physics: ScrollPhysics(),
itemBuilder: (context, index) => Padding(
padding: EdgeInsets.only(bottom: 25),
child: podcastList(index + 1),
),
),
Visibility(
child: SizedBox(
height: 80,
),
replacement: SizedBox(),
visible: playOrNot,
)
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: playOrNot
? Container(
width: Get.size.width,
height: 100,
decoration: BoxDecoration(
color: ColorConstants.kPrimaryColor,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Align(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.asset(
'assets/image/avatar.png',
width: 57,
height: 57,
fit: BoxFit.cover,
),
),
),
),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Ep.25- Set To Inspire:',
style: TextStyle(
fontSize: 14,
color: ColorConstants.kBlack,
fontFamily: 'SFPRO',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
// SizedBox(height: 5),
Text(
'Our Daily Podcast',
style: TextStyle(
fontSize: 14,
color: ColorConstants.kBlack,
fontFamily: 'SFPRO',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
SizedBox(height: 5),
SizedBox(
height: 20,
child: Stack(
children: [
Positioned(
left: -20,
right: 0,
top: 0,
bottom: 0,
child: SliderTheme(
data: SliderThemeData(
trackHeight: 2.0,
thumbColor: Colors.black,
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 0.0,
),
inactiveTrackColor: Colors.black,
activeTrackColor: Colors.white,
),
child: Slider(
min: 0,
max: duration!.inSeconds.toDouble(),
divisions: 100,
activeColor: Colors.black,
inactiveColor: Colors.white,
value: value,
onChanged: (v) {
setState(() {
value = v;
});
},
onChangeEnd: (newValue) async {
setState(() {
value = newValue;
});
player.pause();
await player.seek(
Duration(
seconds: newValue.toInt(),
),
);
await player.resume();
},
),
),
),
],
),
)
],
),
),
Expanded(
flex: 1,
child: InkWell(
onTap: () async {
if (isplaying) {
await player.pause();
setState(() {
isplaying = false;
});
} else {
await player.resume();
player.onPositionChanged.listen(
(position) {
setState(
() {
value = position.inSeconds.toDouble();
},
);
},
);
setState(
() {
isplaying = true;
},
);
}
},
child: Icon(
isplaying ? Icons.pause : Icons.play_arrow_rounded,
size: 50,
color: ColorConstants.kBlack,
),
),
),
],
),
)
: SizedBox(),
),
);
}
podcastList(int index) {
return Row(
children: [
Expanded(
flex: 0,
child: Text(
index.toString(),
style: TextStyle(
fontSize: 14,
color: ColorConstants.kWhite,
fontFamily: 'SFPRO',
),
),
),
Expanded(
flex: 1,
child: Align(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.asset(
'assets/image/avatar.png',
width: 57,
height: 57,
fit: BoxFit.cover,
)),
),
),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'Ep.25- Set To Inspire:',
style: TextStyle(
fontSize: 14,
color: ColorConstants.kWhite,
fontFamily: 'SFPRO',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
SizedBox(height: 5),
Text(
'Our Daily Podcast',
style: TextStyle(
fontSize: 14,
color: ColorConstants.kWhite,
fontFamily: 'SFPRO',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
],
),
),
Expanded(
flex: 0,
child: InkWell(
onTap: () {
setState(() {
playOrNot = true;
isplaying = true;
});
setState(() async {
await player.resume();
player.onPositionChanged.listen(
(position) {
setState(
() {
value = position.inSeconds.toDouble();
},
);
},
);
// if (player.getDuration() == 0) {
// isplaying = false;
// }
});
},
child: Icon(
Icons.play_arrow_rounded,
size: 50,
color: ColorConstants.kWhite,
),
),
),
],
);
}
}