300 lines
11 KiB
Dart
300 lines
11 KiB
Dart
// ignore_for_file: deprecated_member_use
|
|
|
|
import 'dart:async';
|
|
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/routes/routes.dart';
|
|
import 'package:didvan/views/home/media/widgets/featured_video_card.dart';
|
|
import 'package:didvan/views/home/media/widgets/videocast_grid_card.dart';
|
|
import 'package:didvan/views/podcasts/podcasts_state.dart';
|
|
import 'package:didvan/views/widgets/overview/podcast.dart';
|
|
import 'package:didvan/views/widgets/state_handlers/empty_result.dart';
|
|
import 'package:didvan/views/widgets/state_handlers/state_handler.dart';
|
|
import 'package:didvan/views/widgets/item_title.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class VideoCastTabPage extends StatefulWidget {
|
|
const VideoCastTabPage({super.key});
|
|
|
|
@override
|
|
State<VideoCastTabPage> createState() => _VideoCastTabPageState();
|
|
}
|
|
|
|
class _VideoCastTabPageState extends State<VideoCastTabPage> {
|
|
int _currentFeaturedIndex = 0;
|
|
Timer? _rotationTimer;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Future.microtask(() {
|
|
context.read<PodcastsState>().init(false);
|
|
context.read<PodcastsState>().getStudios(page: 1);
|
|
});
|
|
}
|
|
|
|
void _startRotation() {
|
|
_rotationTimer?.cancel();
|
|
_rotationTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
|
final state = context.read<PodcastsState>();
|
|
if (state.studios.isNotEmpty && mounted) {
|
|
setState(() {
|
|
_currentFeaturedIndex =
|
|
(_currentFeaturedIndex + 1) % state.studios.length;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
void _showSortDialog() {
|
|
final state = context.read<PodcastsState>();
|
|
showModalBottomSheet(
|
|
backgroundColor: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 30, 30, 30)
|
|
: Colors.white,
|
|
context: context,
|
|
builder: (context) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.only(bottom: 8.0, right: 16.0, top: 8.0),
|
|
child: Row(
|
|
children: [
|
|
SvgPicture.asset('lib/assets/icons/Sort Regular.svg'),
|
|
const SizedBox(
|
|
width: 5,
|
|
),
|
|
Text(
|
|
'مرتبسازی',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleMedium
|
|
?.copyWith(fontWeight: FontWeight.bold),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text('جدیدترینها'),
|
|
leading: Radio<int>(
|
|
value: 0,
|
|
groupValue: state.selectedSortTypeIndex,
|
|
onChanged: (int? value) {
|
|
if (value != null) {
|
|
state.selectedSortTypeIndex = value;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
activeColor: const Color.fromARGB(255, 178, 4, 54),
|
|
),
|
|
onTap: () {
|
|
state.selectedSortTypeIndex = 0;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
title: const Text('قدیمیترینها'),
|
|
leading: Radio<int>(
|
|
value: 1,
|
|
groupValue: state.selectedSortTypeIndex,
|
|
onChanged: (int? value) {
|
|
if (value != null) {
|
|
state.selectedSortTypeIndex = value;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
activeColor: const Color.fromARGB(255, 178, 4, 54),
|
|
),
|
|
onTap: () {
|
|
state.selectedSortTypeIndex = 1;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
title: const Text('پربازدیدترینها'),
|
|
leading: Radio<int>(
|
|
value: 2,
|
|
groupValue: state.selectedSortTypeIndex,
|
|
onChanged: (int? value) {
|
|
if (value != null) {
|
|
state.selectedSortTypeIndex = value;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
activeColor: const Color.fromARGB(255, 178, 4, 54),
|
|
),
|
|
onTap: () {
|
|
state.selectedSortTypeIndex = 2;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
title: const Text('پربحثترینها'),
|
|
leading: Radio<int>(
|
|
value: 3,
|
|
groupValue: state.selectedSortTypeIndex,
|
|
onChanged: (int? value) {
|
|
if (value != null) {
|
|
state.selectedSortTypeIndex = value;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
activeColor: const Color.fromARGB(255, 178, 4, 54),
|
|
),
|
|
onTap: () {
|
|
state.selectedSortTypeIndex = 3;
|
|
state.getStudios(page: 1);
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_rotationTimer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.watch<PodcastsState>();
|
|
|
|
return StateHandler<PodcastsState>(
|
|
state: state,
|
|
emptyState: EmptyResult(
|
|
onNewSearch: () {},
|
|
),
|
|
enableEmptyState: state.studios.isEmpty,
|
|
placeholder: PodcastOverview.placeholder,
|
|
builder: (context, state) {
|
|
if (state.studios.isEmpty) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
if (_rotationTimer == null || !_rotationTimer!.isActive) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_startRotation();
|
|
});
|
|
}
|
|
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 500),
|
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
|
return FadeTransition(opacity: animation, child: child);
|
|
},
|
|
child: FeaturedVideoCard(
|
|
key: ValueKey<int?>(state.studios[_currentFeaturedIndex].id),
|
|
videocast: state.studios[_currentFeaturedIndex],
|
|
onTap: () {
|
|
Navigator.pushNamed(
|
|
context,
|
|
Routes.videoDetails,
|
|
arguments: {
|
|
'id': state.studios[_currentFeaturedIndex].id,
|
|
'type': state.studios[_currentFeaturedIndex].type,
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
if (state.studios.length > 1)
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
ItemTitle(
|
|
title: 'همه ویدیوکستها',
|
|
color: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 0, 90, 119)
|
|
: const Color.fromARGB(255, 0, 53, 70),
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold, fontSize: 18),
|
|
),
|
|
Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: _showSortDialog,
|
|
child: Text(
|
|
state.orderString,
|
|
style: TextStyle(
|
|
color: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 0, 90, 119)
|
|
: const Color.fromARGB(255, 0, 53, 70)),
|
|
)),
|
|
IconButton(
|
|
onPressed: _showSortDialog,
|
|
icon: SvgPicture.asset(
|
|
'lib/assets/icons/sort2.svg',
|
|
color: DesignConfig.isDark
|
|
? const Color.fromARGB(255, 0, 90, 119)
|
|
: const Color.fromARGB(255, 0, 53, 70),
|
|
)),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (state.studios.length > 1)
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate:
|
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 12,
|
|
mainAxisSpacing: 12,
|
|
childAspectRatio: 0.75,
|
|
),
|
|
itemCount: state.studios.length,
|
|
itemBuilder: (context, index) {
|
|
final videocast = state.studios[index];
|
|
return VideocastGridCard(
|
|
videocast: videocast,
|
|
onTap: () {
|
|
Navigator.pushNamed(
|
|
context,
|
|
Routes.videoDetails,
|
|
arguments: {
|
|
'id': videocast.id,
|
|
'type': videocast.type,
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
onRetry: () => context.read<PodcastsState>().getStudios(page: 1),
|
|
);
|
|
}
|
|
}
|