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