studio error handlign + bug fixes
This commit is contained in:
parent
91d8469d19
commit
56f8b38693
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/constants/app_icons.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/requests/studio.dart';
|
||||
import 'package:didvan/models/view/action_sheet_data.dart';
|
||||
import 'package:didvan/routes/routes.dart';
|
||||
|
|
@ -18,6 +19,7 @@ import 'package:didvan/views/widgets/didvan/divider.dart';
|
|||
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
||||
import 'package:didvan/views/widgets/didvan/radial_button.dart';
|
||||
import 'package:didvan/views/widgets/item_title.dart';
|
||||
import 'package:didvan/views/widgets/state_handlers/empty_result.dart';
|
||||
import 'package:didvan/views/widgets/state_handlers/sliver_state_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
|
@ -41,89 +43,91 @@ class _StudioState extends State<Studio> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Row(
|
||||
children: [
|
||||
const Expanded(child: LogoAppBar(type: 'studio')),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.bookmark_regular,
|
||||
onPressed: () => Navigator.of(context).pushNamed(
|
||||
Routes.filteredBookmarks,
|
||||
arguments: {
|
||||
'type': context.read<StudioState>().type,
|
||||
'onDeleted': (_) {}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SliverToBoxAdapter(
|
||||
child: StudioTabBar(),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SearchField(
|
||||
title: 'استودیو',
|
||||
onChanged: _onChanged,
|
||||
focusNode: _focusNode,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Consumer<StudioState>(
|
||||
builder: (context, state, child) => AnimatedVisibility(
|
||||
isVisible: !state.searching,
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
child: const StudioSlider(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SliverPadding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: DidvanDivider(
|
||||
verticalPadding: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
sliver: SliverToBoxAdapter(
|
||||
return Consumer<StudioState>(
|
||||
builder: (context, state, child) => CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Consumer<StudioState>(
|
||||
builder: (context, state, child) => AnimatedVisibility(
|
||||
isVisible: !state.searching,
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
child: ItemTitle(title: state.orderString),
|
||||
const Expanded(child: LogoAppBar(type: 'studio')),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.bookmark_regular,
|
||||
onPressed: () => Navigator.of(context).pushNamed(
|
||||
Routes.filteredBookmarks,
|
||||
arguments: {'type': state.type, 'onDeleted': (_) {}},
|
||||
),
|
||||
),
|
||||
),
|
||||
DidvanIconButton(
|
||||
gestureSize: 36,
|
||||
icon: DidvanIcons.sort_regular,
|
||||
onPressed: _showSortDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Consumer<StudioState>(
|
||||
builder: (context, state, child) => SliverStateHandler<StudioState>(
|
||||
const SliverToBoxAdapter(
|
||||
child: StudioTabBar(),
|
||||
),
|
||||
if (state.appState != AppState.failed)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SearchField(
|
||||
title: 'استودیو',
|
||||
onChanged: _onChanged,
|
||||
focusNode: _focusNode,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (state.appState != AppState.failed)
|
||||
SliverToBoxAdapter(
|
||||
child: AnimatedVisibility(
|
||||
isVisible: !state.searching,
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
child: const StudioSlider(),
|
||||
),
|
||||
),
|
||||
if (state.appState != AppState.failed && state.studios.isNotEmpty)
|
||||
const SliverPadding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: DidvanDivider(
|
||||
verticalPadding: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (state.appState != AppState.failed && state.studios.isNotEmpty)
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
AnimatedVisibility(
|
||||
isVisible: !state.searching,
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
child: ItemTitle(title: state.orderString),
|
||||
),
|
||||
DidvanIconButton(
|
||||
gestureSize: 36,
|
||||
icon: DidvanIcons.sort_regular,
|
||||
onPressed: _showSortDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverStateHandler<StudioState>(
|
||||
state: state,
|
||||
itemPadding: const EdgeInsets.only(
|
||||
bottom: 8,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
emptyState: EmptyResult(
|
||||
onNewSearch: () => _focusNode.requestFocus(),
|
||||
),
|
||||
centerEmptyState: false,
|
||||
enableEmptyState: state.studios.isEmpty,
|
||||
placeholder: state.videosSelected
|
||||
? VideoOverview.placeHolder
|
||||
: PodcastOverview.placeholder,
|
||||
|
|
@ -154,8 +158,8 @@ class _StudioState extends State<Studio> {
|
|||
childCount: state.studios.length,
|
||||
onRetry: () => state.getStudios(page: 1),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,13 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
return Consumer<StudioDetailsState>(
|
||||
builder: (context, state, child) => StateHandler<StudioDetailsState>(
|
||||
state: state,
|
||||
onRetry: () => state.getStudioDetails(state.studio.id),
|
||||
onRetry: () {
|
||||
try {
|
||||
state.getStudioDetails(state.studio.id);
|
||||
} catch (e) {
|
||||
state.getStudioDetails(widget.pageData['id']);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ class _SearchFieldState extends State<SearchField> {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.focusNode.removeListener(() {});
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,134 +118,138 @@ class _PlayerNavBar extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
alignment: Alignment.topCenter,
|
||||
child: !_enablePlayerController(state)
|
||||
? const SizedBox()
|
||||
: MediaService.currentPodcast == null
|
||||
? SizedBox(
|
||||
height: 32,
|
||||
child: Center(
|
||||
child: SpinKitThreeBounce(
|
||||
size: 18,
|
||||
child: Builder(builder: (context) {
|
||||
if (!_enablePlayerController(state)) return const SizedBox();
|
||||
if (state.appState == AppState.failed) {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
MediaService.resetAudioPlayer();
|
||||
});
|
||||
return DidvanText(
|
||||
'اتصال اینترنت برقرار نمیباشد',
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.title
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
);
|
||||
}
|
||||
if (MediaService.currentPodcast == null) {
|
||||
return SizedBox(
|
||||
height: 32,
|
||||
child: Center(
|
||||
child: SpinKitThreeBounce(
|
||||
size: 18,
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.title
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 12,
|
||||
left: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.close_regular,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
gestureSize: 28,
|
||||
onPressed: MediaService.resetAudioPlayer,
|
||||
),
|
||||
),
|
||||
SkeletonImage(
|
||||
imageUrl: MediaService.currentPodcast!.image,
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DidvanText(
|
||||
MediaService.currentPodcast!.title,
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.title
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 12,
|
||||
left: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.close_regular,
|
||||
AudioSlider(
|
||||
disableThumb: true,
|
||||
tag: MediaService.audioPlayerTag!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream: MediaService.audioPlayer.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
final playerState = MediaService
|
||||
.audioPlayer.playerState.processingState;
|
||||
if (playerState == ProcessingState.loading ||
|
||||
state.appState == AppState.busy) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 18,
|
||||
width: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
? Theme.of(context).colorScheme.title
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
gestureSize: 28,
|
||||
onPressed: MediaService.resetAudioPlayer,
|
||||
),
|
||||
),
|
||||
SkeletonImage(
|
||||
imageUrl: MediaService.currentPodcast!.image,
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DidvanText(
|
||||
MediaService.currentPodcast!.title,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
AudioSlider(
|
||||
disableThumb: true,
|
||||
tag: MediaService.audioPlayerTag!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream:
|
||||
MediaService.audioPlayer.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
final playerState = MediaService
|
||||
.audioPlayer.playerState.processingState;
|
||||
if (playerState == ProcessingState.loading ||
|
||||
state.appState == AppState.busy) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 18,
|
||||
width: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.title
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
if (state.appState != AppState.busy &&
|
||||
MediaService.audioPlayer.playerState
|
||||
.processingState !=
|
||||
ProcessingState.loading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
gestureSize: 28,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
icon: snapshot.data!
|
||||
? DidvanIcons.pause_solid
|
||||
: DidvanIcons.play_solid,
|
||||
onPressed: () {
|
||||
if (state.args.type == 'video') {
|
||||
state.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: state.podcastArgs,
|
||||
forceFetch: true,
|
||||
);
|
||||
}
|
||||
MediaService.handleAudioPlayback(
|
||||
audioSource:
|
||||
MediaService.currentPodcast!.media,
|
||||
id: MediaService.currentPodcast!.id,
|
||||
isVoiceMessage: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
if (state.appState != AppState.busy &&
|
||||
MediaService.audioPlayer.playerState.processingState !=
|
||||
ProcessingState.loading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
gestureSize: 28,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
icon: snapshot.data!
|
||||
? DidvanIcons.pause_solid
|
||||
: DidvanIcons.play_solid,
|
||||
onPressed: () {
|
||||
if (state.args.type == 'video') {
|
||||
state.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: state.podcastArgs,
|
||||
forceFetch: true,
|
||||
);
|
||||
}
|
||||
MediaService.handleAudioPlayback(
|
||||
audioSource: MediaService.currentPodcast!.media,
|
||||
id: MediaService.currentPodcast!.id,
|
||||
isVoiceMessage: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue