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

226 lines
6.5 KiB
Dart

// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gsp_app/views/pages/podcast/podcats_manager.dart';
import '../../components/appbar.dart';
import '../../theme.dart';
import 'podcast_list_audio.dart';
import 'viewModel/PodcastApis.dart';
class PodcastMain extends StatefulWidget {
const PodcastMain({Key? key}) : super(key: key);
@override
State<PodcastMain> createState() => _PodcastMainState();
}
class _PodcastMainState extends State<PodcastMain> {
Future? myfuture;
List<String> itemList = [
'Latest',
// 'Most Played',
// 'Self Help',
];
@override
void initState() {
myfuture = PodcastApis().getPodcasts();
super.initState();
}
Visible visibleController = Get.put(Visible());
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ColorConstants.kBlack,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60),
child: CustomAppBars(titleHead: 'Podcasts'),
),
body: FutureBuilder(
future: myfuture,
builder: (ctx, snapshot) {
if (snapshot.data == null) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [Center(child: CircularProgressIndicator())],
);
}
if (snapshot.connectionState == ConnectionState.done) {
visibleController.addTitles();
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occured',
style: TextStyle(fontSize: 18),
),
);
}
}
return _buildBody();
},
),
);
}
_buildBody() {
return SingleChildScrollView(
physics: ScrollPhysics(),
child: Column(
children: [
Container(
height: 300,
width: Get.size.width,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/image/podcast/podcastImg.jpg',
),
alignment: Alignment.topCenter,
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Spacer(flex: 3),
// 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,
// ),
// ),
SizedBox(height: 10),
Text(
'Weekly Podcasts',
style: TextStyle(
fontSize: 18,
color: ColorConstants.kWhite,
),
),
Spacer(flex: 1),
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: ListView.builder(
shrinkWrap: true,
physics: ScrollPhysics(),
itemCount: itemList.length,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) => Column(
children: [
headWithArrow(
itemList[index],
() => Get.to(
() => const PodcastAudioPalyer(),
),
),
const SizedBox(height: 15),
podcast(),
SizedBox(height: 30)
],
),
),
),
],
),
);
}
podcast() {
return SizedBox(
height: 170,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: pods?.result?.latestPodcast?.length ?? 0,
itemBuilder: (context, index) => GestureDetector(
onTap: () {
Get.to(() => PodcastAudioPalyer());
},
child: Padding(
padding: const EdgeInsets.only(left: 8, right: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: SizedBox(
width: 94,
height: 94,
child: Image.network(
pods!.result!.latestPodcast![index].bannerImage!,
fit: BoxFit.cover,
),
),
),
),
const SizedBox(height: 10),
Text(
pods!.result!.latestPodcast![index].title!,
style: TextStyle(
fontSize: 12,
color: Color(0xffFFFFFF),
),
),
SizedBox(
height: 5,
),
Image.asset('assets/image/music.png'),
SizedBox(
height: 5,
),
// const Text(
// '0.30 Min',
// style: TextStyle(
// fontSize: 10,
// color: ColorConstants.kWhite,
// ),
// )
],
),
),
),
),
);
}
headWithArrow(String head, VoidCallback ontap) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
head,
style: const TextStyle(
fontSize: 17,
color: Color(0xffD9D9D9),
),
),
InkWell(
onTap: ontap,
child: const Icon(
Icons.keyboard_arrow_right,
color: ColorConstants.kWhite,
size: 30,
),
)
],
);
}
}