Files
Traders_Circuit/lib/view/Sidemenu/ContentByte/AudioMore.dart
2024-05-09 15:17:24 +05:30

481 lines
21 KiB
Dart

import 'dart:developer';
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:get/get.dart';
import 'package:traderscircuit/Utils/Common/CommonAppbar.dart';
import 'package:traderscircuit/Utils/Common/CustomTextFormField.dart';
import 'package:traderscircuit/Utils/Common/sized_box.dart';
import 'package:traderscircuit/Utils/text.dart';
import 'package:traderscircuit/controller/content_bytes_controller.dart';
import 'package:traderscircuit/model/ContentBytesModel/content_bytes_model.dart';
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
import 'package:traderscircuit/view_model/ContentBytesApi/content_bytes_api.dart';
import '../../../Utils/Common/comonGlassmorphicContainer.dart';
import 'ContentBytes.dart';
class AudioMore extends StatefulWidget {
const AudioMore({super.key});
@override
State<AudioMore> createState() => _VideosMoreState();
}
class _VideosMoreState extends State<AudioMore> {
ContentBytesController contentBytesController =
Get.put(ContentBytesController());
var data;
RxBool isLoading = true.obs;
RxInt selectedFilterIndex = 100.obs;
TextEditingController searchController = TextEditingController();
@override
void initState() {
ContentBytesApi().getContentBytesData("", "audio", "").then((value) {
contentBytesController.moreAudioModel =
ContentBytesModel.fromJson(value.data);
isLoading.value = false;
setState(() {});
});
super.initState();
}
void handleSearch(String query, String category) async {
await ContentBytesApi()
.getContentBytesData(
query, "audio", contentBytesController.filterId.toString())
.then((value) {
contentBytesController.moreAudioModel =
ContentBytesModel.fromJson(value.data);
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return PopScope(
canPop: true,
onPopInvoked: (didPop) {
if (contentBytesController.isAudioInitialize) {
contentBytesController.isAudioSeekBarVisible.value = false;
contentBytesController.pause();
contentBytesController.stop();
}
},
child: Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Obx(
() => contentBytesController.isAudioSeekBarVisible.value
? commonGlassContainer(
borderradius: 8,
width: Get.size.width,
height: 100,
customWidget: Row(
children: [
Expanded(
flex: 1,
child: Align(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.network(
contentBytesController
.moreAudioModel
.data!
.audio![contentBytesController
.indexForAudios.value]
.image!,
width: 57,
height: 57,
fit: BoxFit.cover,
),
),
),
),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
contentBytesController
.moreAudioModel
.data!
.audio![contentBytesController
.indexForAudios.value]
.title!,
style: const TextStyle(
fontSize: 14,
color: Colors.white,
fontFamily: 'hiragino',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
// SizedBox(height: 5),
Text(
contentBytesController
.moreAudioModel
.data!
.audio![contentBytesController
.indexForAudios.value]
.description!,
style: const TextStyle(
fontSize: 14,
color: Colors.white,
fontFamily: 'hiragino',
fontWeight: FontWeight.w600,
height: 1.5,
),
),
ValueListenableBuilder<ProgressBarState>(
valueListenable:
contentBytesController.progressNotifier,
builder: (context, value, _) {
return ProgressBar(
progress: value.current,
buffered: value.buffered,
total: value.total,
onSeek: contentBytesController.seek,
barHeight: 4,
thumbRadius: 6,
thumbGlowRadius: 15,
timeLabelTextStyle: const TextStyle(
color: Colors.white,
),
thumbColor: Colors.white,
baseBarColor: Colors.white.withOpacity(0.3),
progressBarColor: Colors.white,
bufferedBarColor:
Colors.white.withOpacity(0.3),
);
},
),
],
),
),
Expanded(
flex: 1,
child: ValueListenableBuilder<ButtonState>(
valueListenable:
contentBytesController.buttonNotifier,
builder: (context, value, _) {
switch (value) {
case ButtonState.paused:
return IconButton(
icon: const Icon(
Icons.play_arrow_rounded,
color: Colors.white,
),
iconSize: 50.0,
onPressed: () => contentBytesController.play(
contentBytesController
.indexForAudios.value),
);
case ButtonState.playing:
return IconButton(
icon: const Icon(Icons.pause,
color: Colors.white),
iconSize: 50.0,
onPressed: contentBytesController.pause,
);
}
},
),
),
],
),
)
: Container(),
),
appBar: const CommonAppbar(
titleTxt: "Audio",
),
backgroundColor: Colors.black,
extendBody: true,
body: Obx(
() => Stack(
children: [
const CommonBlurLeft(),
const CommonBlurRight(),
isLoading.value
? const Center(
child: CircularProgressIndicator(
color: Color(0xFF9A0000),
),
)
: Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16W400_DADADA(
'The Beauty and Power of Audios'),
sizedBoxHeight(8.w),
Row(
children: [
SizedBox(
width: 295.w,
child: CustomTextFormField(
textEditingController: searchController,
onInput: (value) {
// Call method to handle search
handleSearch(value, "");
},
hintText: "Search Audio",
),
),
SizedBox(
width: 12.w,
),
filter(),
],
),
sizedBoxHeight(20.h),
contentBytesController
.moreAudioModel.data!.audio!.isEmpty
? Center(
child: Column(
children: [
const Gap(250),
text24W500("No Data Found !"),
],
))
: GridView.builder(
shrinkWrap: true,
physics:
const NeverScrollableScrollPhysics(),
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 172,
crossAxisCount:
2, // number of items in each row
mainAxisSpacing:
8.0, // spacing between rows
crossAxisSpacing:
8.0, // spacing between columns
),
itemCount: contentBytesController
.moreAudioModel
.data!
.audio!
.length, // total number of items
itemBuilder: (context, index) {
return InkWell(
onTap: () {
if (contentBytesController
.isAudioInitialize) {
contentBytesController
.isAudioSeekBarVisible
.value = false;
contentBytesController.pause();
contentBytesController.stop();
}
contentBytesController.init(
index, "regular");
contentBytesController
.isAudioSeekBarVisible
.value = true;
//https://actions.google.com/sounds/v1/horror/aggressive_zombie_snarls.ogg
},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.white.withOpacity(0.1),
const Color(0xFFFFFFFF)
.withOpacity(0.05),
],
stops: const [
0.1,
1,
],
),
borderRadius:
BorderRadius.circular(8),
),
child: Stack(
children: [
Image.network(
contentBytesController
.moreAudioModel
.data!
.audio![index]
.image!,
),
Positioned(
bottom: 5,
left: 5,
child: Row(
children: [
CircleAvatar(
radius: 18.sp,
child: const Icon(
Icons.headphones),
),
SizedBox(
width: 5.w,
),
SizedBox(
width: 125.w,
child: text14W500(
contentBytesController
.moreAudioModel
.data!
.audio![index]
.title!),
),
],
),
),
],
),
),
);
},
),
],
),
),
],
),
],
),
),
),
);
}
Widget filter() {
return PopupMenuButton(
icon: Image.asset(
"assets/images/png/filter.png",
height: 30.h,
width: 30.w,
),
color: const Color(0xFF191919),
itemBuilder: (context) {
return [
PopupMenuItem(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SizedBox(
height: (Get.height *
contentBytesController
.contentBytesCategoriesModel.data!.length) /
12,
width: 180,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: contentBytesController
.contentBytesCategoriesModel.data!.length +
1,
itemBuilder: (ctx, index) {
return index == 0
? selectedFilterIndex.value == 100
? SizedBox()
: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
GestureDetector(
onTap: (() {
Get.back();
selectedFilterIndex.value = 100;
contentBytesController.filterId =
"";
handleSearch("", "");
}),
child: text16W600("Reset",
clr: const Color(0xFF9A0000)))
],
)
: InkWell(
onTap: () {
// contentBytesController.isApiCalling.value = true;
Get.back();
selectedFilterIndex.value = index - 1;
contentBytesController.filterId =
contentBytesController
.contentBytesCategoriesModel
.data![index - 1]
.id!
.toString();
handleSearch(
searchController.text,
contentBytesController.filterId
.toString());
},
child: itemFilter(
index - 1, selectedFilterIndex.value));
}),
),
),
],
))
];
},
);
}
Widget itemFilter(int index, int selectedIndex) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Gap(8),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
selectedIndex == index
? const CircleAvatar(
radius: 12,
backgroundColor: Colors.white,
child: Center(
child: Icon(
Icons.check,
color: Colors.green,
),
),
)
: const SizedBox(),
selectedIndex == index ? const Gap(5) : const SizedBox(),
SizedBox(
width: 150,
child: text18W400(
contentBytesController
.contentBytesCategoriesModel.data![index].categoryName!,
texAl: TextAlign.center,
),
),
],
),
index ==
contentBytesController
.contentBytesCategoriesModel.data!.length -
1
? const SizedBox()
: const Divider(
color: Color(0xFF2C2C2C),
thickness: 0.6,
endIndent: 0,
),
],
);
}
}