bug fixes

This commit is contained in:
MohammadTaha Basiri 2022-04-17 13:37:57 +04:30
parent 27e44fb764
commit e865f15f70
6 changed files with 121 additions and 83 deletions

View File

@ -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<void> _getDirectTypes() async {
final service = RequestService(RequestHelper.directTypes);

View File

@ -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<void> handleAudioPlayback({
required dynamic audioSource,

View File

@ -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<News> {
@override
Widget build(BuildContext context) {
return Consumer<NewsState>(
builder: (context, state, child) => StateHandler<NewsState>(
final state = context.watch<NewsState>();
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<NewsState>(
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,
),
],
);
}

View File

@ -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(),

View File

@ -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),
],
),
],
),
],
),
),
],
);
}

View File

@ -13,6 +13,7 @@ class SliverStateHandler<T extends CoreProvier> 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<T extends CoreProvier> 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<T extends CoreProvier> 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,