diff --git a/lib/providers/server_data.dart b/lib/providers/server_data.dart index 4ef71bb..3468d29 100644 --- a/lib/providers/server_data.dart +++ b/lib/providers/server_data.dart @@ -9,12 +9,18 @@ class ServerDataProvider { await _getDirectTypes(); } - static int labelToTypeId(String label) => label.contains('پشتیبانی') - ? 7 - : directTypes + static int labelToTypeId(String label) { + if (label.contains('پشتیبانی اپلیکیشن')) { + return 8; + } else if (label.contains('پشتیبانی')) { + return 7; + } else { + return directTypes .firstWhereOrNull((element) => element.value.contains(label)) ?.key ?? 7; + } + } static Future _getDirectTypes() async { final service = RequestService(RequestHelper.directTypes); diff --git a/lib/services/media/media.dart b/lib/services/media/media.dart index a783e23..2342acd 100644 --- a/lib/services/media/media.dart +++ b/lib/services/media/media.dart @@ -14,7 +14,8 @@ class MediaService { static StudioDetailsData? currentPodcast; static StudioRequestArgs? podcastPlaylistArgs; - static Duration? get duration => audioPlayer.current.value?.audio.duration; + static Duration? get duration => + audioPlayer.current.valueOrNull?.audio.duration; static Future handleAudioPlayback({ required dynamic audioSource, diff --git a/lib/views/home/news/news.dart b/lib/views/home/news/news.dart index 29cc5d8..bbfed23 100644 --- a/lib/views/home/news/news.dart +++ b/lib/views/home/news/news.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:didvan/constants/app_icons.dart'; +import 'package:didvan/models/enums.dart'; import 'package:didvan/models/requests/news.dart'; import 'package:didvan/models/view/action_sheet_data.dart'; import 'package:didvan/utils/action_sheet.dart'; @@ -10,7 +11,8 @@ import 'package:didvan/views/home/widgets/logo_app_bar.dart'; import 'package:didvan/views/home/widgets/overview/news.dart'; import 'package:didvan/views/home/widgets/search_field.dart'; import 'package:didvan/views/widgets/item_title.dart'; -import 'package:didvan/views/widgets/state_handlers/state_handler.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'; @@ -32,62 +34,58 @@ class _NewsState extends State { @override Widget build(BuildContext context) { - return Consumer( - builder: (context, state, child) => StateHandler( + final state = context.watch(); + return CustomScrollView( + slivers: [ + const SliverToBoxAdapter(child: LogoAppBar()), + if (state.appState != AppState.failed) + SliverPadding( + padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), + sliver: SliverToBoxAdapter( + child: SearchField( + focusNode: _focusNode, + title: 'اخبار', + onChanged: _onChanged, + onFilterButtonPressed: _showFilterBottomSheet, + isFiltered: state.isFiltering, + ), + ), + ), + SliverStateHandler( + centerEmptyState: false, onRetry: () => state.getNews(page: state.page), state: state, - builder: (context, state) => ListView.builder( - cacheExtent: 1500, - itemBuilder: (context, index) { - if (index == 0) { - return const LogoAppBar(); - } - if (index == 1) { - return Padding( - padding: const EdgeInsets.only( - left: 16, - right: 16, - bottom: 16, - ), - child: SearchField( - focusNode: _focusNode, - title: 'اخبار', - onChanged: _onChanged, - onFilterButtonPressed: _showFilterBottomSheet, - isFiltered: state.isFiltering, - ), - ); - } - index -= 2; - index += 2; - if (index % 15 == 0 && state.lastPage != state.page) { - state.getNews(page: state.page + 1); - } - index -= 2; - if (index >= state.news.length) { - return NewsOverview.placeholder; - } - final news = state.news[index]; - return Padding( - padding: const EdgeInsets.only( - left: 16, - right: 16, - bottom: 16, - ), - child: NewsOverview( - news: news, - onMarkChanged: state.onMarkChanged, - newsRequestArgs: NewsRequestArgs( - page: state.page, - endDate: state.endDate, - startDate: state.startDate, - search: state.search, - ), - ), - ); - }, - itemCount: state.news.length + 2, - )), + builder: (context, state, index) { + index += 2; + if (index % 15 == 0 && state.lastPage != state.page) { + state.getNews(page: state.page + 1); + } + index -= 2; + if (index >= state.news.length) { + return NewsOverview.placeholder; + } + final news = state.news[index]; + return NewsOverview( + news: news, + onMarkChanged: state.onMarkChanged, + newsRequestArgs: NewsRequestArgs( + page: state.page, + endDate: state.endDate, + startDate: state.startDate, + search: state.search, + ), + ); + }, + enableEmptyState: state.news.isEmpty, + emptyState: EmptyResult( + onNewSearch: () => _focusNode.requestFocus(), + ), + childCount: + state.news.length + (state.lastPage == state.page ? 0 : 3), + itemPadding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), + placeholder: NewsOverview.placeholder, + ), + ], ); } diff --git a/lib/views/home/settings/settings.dart b/lib/views/home/settings/settings.dart index e923da5..eae023f 100644 --- a/lib/views/home/settings/settings.dart +++ b/lib/views/home/settings/settings.dart @@ -94,7 +94,10 @@ class Settings extends StatelessWidget { icon: DidvanIcons.support_regular, title: 'پیام به پشتیبانی', onTap: () { - launch('mailto:info@didvan.app'); + Navigator.of(context).pushNamed( + Routes.direct, + arguments: {'type': 'پشتیبانی اپلیکیشن'}, + ); }, ), const DidvanDivider(), diff --git a/lib/views/home/statistic/widgets/statistic_overview.dart b/lib/views/home/statistic/widgets/statistic_overview.dart index 52906e5..cfa585e 100644 --- a/lib/views/home/statistic/widgets/statistic_overview.dart +++ b/lib/views/home/statistic/widgets/statistic_overview.dart @@ -108,28 +108,57 @@ class StatisticOverview extends StatelessWidget { ); } - static Widget get placeHolder => DidvanCard( - child: Column( - children: [ - const SizedBox(height: 4), - Row( - children: const [ - ShimmerPlaceholder(width: 80, height: 16), - Spacer(), - ShimmerPlaceholder(width: 50, height: 14), - SizedBox(width: 8), - ShimmerPlaceholder(width: 50, height: 16), + static Widget get placeHolder => Column( + children: [ + DidvanCard( + child: Column( + children: [ + const SizedBox(height: 4), + Row( + children: const [ + ShimmerPlaceholder(width: 80, height: 16), + Spacer(), + ShimmerPlaceholder(width: 50, height: 14), + SizedBox(width: 8), + ShimmerPlaceholder(width: 50, height: 16), + ], + ), + const SizedBox(height: 16), + Row( + children: const [ + ShimmerPlaceholder(width: 150, height: 12), + Spacer(), + ShimmerPlaceholder(width: 80, height: 12), + ], + ), ], ), - const SizedBox(height: 16), - Row( - children: const [ - ShimmerPlaceholder(width: 150, height: 12), - Spacer(), - ShimmerPlaceholder(width: 80, height: 12), + ), + const SizedBox(height: 20), + DidvanCard( + child: Column( + children: [ + const SizedBox(height: 4), + Row( + children: const [ + ShimmerPlaceholder(width: 80, height: 16), + Spacer(), + ShimmerPlaceholder(width: 50, height: 14), + SizedBox(width: 8), + ShimmerPlaceholder(width: 50, height: 16), + ], + ), + const SizedBox(height: 16), + Row( + children: const [ + ShimmerPlaceholder(width: 150, height: 12), + Spacer(), + ShimmerPlaceholder(width: 80, height: 12), + ], + ), ], ), - ], - ), + ), + ], ); } diff --git a/lib/views/widgets/state_handlers/sliver_state_handler.dart b/lib/views/widgets/state_handlers/sliver_state_handler.dart index 1e70ddb..8338a49 100644 --- a/lib/views/widgets/state_handlers/sliver_state_handler.dart +++ b/lib/views/widgets/state_handlers/sliver_state_handler.dart @@ -13,6 +13,7 @@ class SliverStateHandler extends SliverList { final Widget? placeholder; final EdgeInsets? itemPadding; final bool centerEmptyState; + final bool hasConstraints; SliverStateHandler({ Key? key, required this.state, @@ -24,14 +25,16 @@ class SliverStateHandler extends SliverList { this.emptyState, this.enableEmptyState = false, this.centerEmptyState = true, + this.hasConstraints = false, }) : super( key: key, delegate: SliverChildBuilderDelegate( (context, index) { + final deviceHight = MediaQuery.of(context).size.height; if (state.appState == AppState.failed) { return Padding( padding: EdgeInsets.only( - top: centerEmptyState ? 120 : 20, + top: centerEmptyState ? deviceHight / 4 : deviceHight / 8, bottom: 20, ), child: EmptyConnection(onRetry: onRetry), @@ -40,9 +43,7 @@ class SliverStateHandler extends SliverList { if (enableEmptyState && state.appState == AppState.idle) { return Padding( padding: EdgeInsets.only( - top: centerEmptyState - ? MediaQuery.of(context).size.height / 4 - : 20, + top: centerEmptyState ? deviceHight / 4 : deviceHight / 8, bottom: 20, ), child: emptyState,