some changes

This commit is contained in:
mehrdad78 2024-04-13 21:21:57 +03:30
parent d3252e931f
commit dfe506bb01
6 changed files with 670 additions and 431 deletions

View File

@ -7,10 +7,14 @@ import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/utils/action_sheet.dart';
import 'package:didvan/views/home/infography/infography_screen_state.dart';
import 'package:didvan/views/home/main/widgets/infography_item.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/checkbox.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/item_title.dart';
import 'package:didvan/views/widgets/overview/news.dart';
import 'package:didvan/views/widgets/search_field.dart';
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/state_handlers/empty_result.dart';
import 'package:didvan/views/widgets/state_handlers/state_handler.dart';
import 'package:flutter/material.dart';
@ -144,14 +148,6 @@ class _InfographyScreenState extends State<InfographyScreen> {
@override
Widget build(BuildContext context) {
return StateHandler<InfographyScreenState>(
emptyState: EmptyResult(
onNewSearch: () => _focusNode.requestFocus(),
),
enableEmptyState: context.watch<InfographyScreenState>().contents.isEmpty,
onRetry: context.read<InfographyScreenState>().init,
state: context.watch<InfographyScreenState>(),
builder: (context, state) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,
@ -168,24 +164,43 @@ class _InfographyScreenState extends State<InfographyScreen> {
Container(
height: 80,
color: Theme.of(context).colorScheme.surface,
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 16.0),
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: SearchField(
title: "اینفوگرافی",
onChanged: _onChanged,
focusNode: _focusNode,
onFilterButtonPressed: _showFilterBottomSheet,
value: state.lastSearch,
isFiltered: state.filtering),
value: context.watch<InfographyScreenState>().lastSearch,
isFiltered: context.watch<InfographyScreenState>().filtering),
),
Expanded(
StateHandler<InfographyScreenState>(
placeholder: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
placeholder,
const SizedBox(
height: 4,
),
placeholder
],
),
),
emptyState: EmptyResult(
onNewSearch: () => _focusNode.requestFocus(),
),
enableEmptyState:
context.watch<InfographyScreenState>().contents.isEmpty,
onRetry: context.read<InfographyScreenState>().init,
state: context.watch<InfographyScreenState>(),
builder: (context, state) => Expanded(
child: ListView.builder(
controller: _scrollController,
itemCount: state.contents.length,
itemBuilder: (context, index) => InfographyItem(
id: state.contents[index].id,
onMarkChanged: (id, value, _) =>
state.changeMark(id, value),
onMarkChanged: (id, value, _) => state.changeMark(id, value),
image: state.contents[index].image,
category: state.contents[index].category,
createdAt: state.contents[index].createdAt,
@ -195,10 +210,47 @@ class _InfographyScreenState extends State<InfographyScreen> {
),
),
),
),
],
),
);
},
);
}
static Widget get placeholder => const DidvanCard(
margin: EdgeInsets.all(8),
padding: EdgeInsets.all(8),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShimmerPlaceholder(
height: 16,
width: 240,
),
],
),
SizedBox(height: 12),
ShimmerPlaceholder(height: 200, width: 400),
SizedBox(height: 12),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShimmerPlaceholder(
height: 32,
width: 100,
),
],
),
DidvanDivider(
verticalPadding: 12,
),
ShimmerPlaceholder(
height: 16,
width: double.infinity,
),
],
),
);
}

View File

@ -9,6 +9,7 @@ import 'package:didvan/views/home/new_statistic/widgets/statistic_cat.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/state_handlers/state_handler.dart';
import 'package:flutter/material.dart';
@ -37,10 +38,7 @@ class _NewStatisticState extends State<NewStatistic> {
@override
Widget build(BuildContext context) {
return StateHandler<NewStatisticState>(
onRetry: context.read<NewStatisticState>().init,
state: context.watch<NewStatisticState>(),
builder: (context, state) => Padding(
return Padding(
padding: const EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: Column(
@ -69,13 +67,40 @@ class _NewStatisticState extends State<NewStatistic> {
const DidvanDivider(
verticalPadding: 4,
),
StateHandler<NewStatisticState>(
enableEmptyState: false,
onRetry: context.read<NewStatisticState>().init,
state: context.watch<NewStatisticState>(),
placeholder: Padding(
padding: const EdgeInsets.only(top: 48.0),
child: Column(
children: [
placeholder,
SizedBox(
height: 8,
),
placeholder,
SizedBox(
height: 8,
),
placeholder,
SizedBox(
height: 8,
),
placeholder,
],
),
),
builder: (context, state) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
GestureDetector(
onTap: () => Future.delayed(Duration.zero, () {
Navigator.of(context)
.pushNamed(Routes.statGeneral, arguments: {
"id": 7,
"title": state.contents[0].header,
}).then((value) => state.getStatistic());
}).then((value) => _reset());
}),
child: StatHeader(
header: state.contents[0].header,
@ -150,7 +175,10 @@ class _NewStatisticState extends State<NewStatistic> {
GestureDetector(
onTap: () => Future.delayed(Duration.zero, () {
Navigator.of(context).pushNamed(Routes.statGeneral,
arguments: {"id": 3, "title": state.contents[3].header});
arguments: {
"id": 3,
"title": state.contents[3].header
});
}).then((value) => _reset()),
child: StatHeader(
header: state.contents[3].header,
@ -221,9 +249,61 @@ class _NewStatisticState extends State<NewStatistic> {
],
),
),
],
),
),
);
}
static Widget get placeholder => const Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
height: 16,
width: 100,
),
ShimmerPlaceholder(
height: 16,
width: 50,
)
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
DidvanCard(
child: ShimmerPlaceholder(
height: 80,
width: 60,
),
),
DidvanCard(
child: ShimmerPlaceholder(
height: 80,
width: 60,
),
),
DidvanCard(
child: ShimmerPlaceholder(
height: 80,
width: 60,
),
),
DidvanCard(
child: ShimmerPlaceholder(
height: 80,
width: 60,
),
),
],
),
],
);
}
class StatMainCard extends StatelessWidget {

View File

@ -2,8 +2,10 @@ import 'dart:async';
import 'package:didvan/views/home/new_statistic/statistics_details/stat_cats_general_state.dart';
import 'package:didvan/views/home/new_statistic/widgets/general_stat_card.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/search_field.dart';
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/state_handlers/empty_result.dart';
import 'package:didvan/views/widgets/state_handlers/state_handler.dart';
import 'package:flutter/material.dart';
@ -74,15 +76,6 @@ class _StatGeneralScreenState extends State<StatGeneralScreen> {
@override
Widget build(BuildContext context) {
return StateHandler<StatGeneralScreenState>(
onRetry: context.read<StatGeneralScreenState>().init,
state: context.watch<StatGeneralScreenState>(),
emptyState: EmptyResult(
onNewSearch: () => _focusNode.requestFocus(),
),
enableEmptyState:
context.watch<StatGeneralScreenState>().contents.isEmpty,
builder: (context, state) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
@ -99,13 +92,13 @@ class _StatGeneralScreenState extends State<StatGeneralScreen> {
Container(
height: 80,
color: Theme.of(context).colorScheme.surface,
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 16.0),
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: SearchField(
title: widget.pageData['title'],
onChanged: _onChanged,
focusNode: _focusNode,
value: state.lastSearch,
value: context.watch<StatGeneralScreenState>().lastSearch,
),
),
Padding(
@ -114,7 +107,28 @@ class _StatGeneralScreenState extends State<StatGeneralScreen> {
alignment: Alignment.centerLeft,
child: DidvanText(formattedDate.toPersianDate())),
),
Expanded(
StateHandler<StatGeneralScreenState>(
onRetry: context.read<StatGeneralScreenState>().init,
state: context.watch<StatGeneralScreenState>(),
emptyState: EmptyResult(
onNewSearch: () => _focusNode.requestFocus(),
),
enableEmptyState:
context.watch<StatGeneralScreenState>().contents.isEmpty,
placeholder: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
placeHolder,
const SizedBox(
height: 8,
),
placeHolder,
const SizedBox(
height: 8,
),
],
),
builder: (context, state) => Expanded(
child: ListView.builder(
controller: _scrollController,
physics: const ClampingScrollPhysics(),
@ -126,10 +140,63 @@ class _StatGeneralScreenState extends State<StatGeneralScreen> {
),
),
),
),
],
),
);
},
);
}
static Widget get placeHolder => const Column(
children: [
DidvanCard(
child: Column(
children: [
SizedBox(height: 4),
Row(
children: [
ShimmerPlaceholder(width: 80, height: 16),
Spacer(),
ShimmerPlaceholder(width: 50, height: 14),
SizedBox(width: 8),
ShimmerPlaceholder(width: 50, height: 16),
],
),
SizedBox(height: 16),
Row(
children: [
ShimmerPlaceholder(width: 150, height: 12),
Spacer(),
ShimmerPlaceholder(width: 80, height: 12),
],
),
],
),
),
SizedBox(height: 20),
DidvanCard(
child: Column(
children: [
SizedBox(height: 4),
Row(
children: [
ShimmerPlaceholder(width: 80, height: 16),
Spacer(),
ShimmerPlaceholder(width: 50, height: 14),
SizedBox(width: 8),
ShimmerPlaceholder(width: 50, height: 16),
],
),
SizedBox(height: 16),
Row(
children: [
ShimmerPlaceholder(width: 150, height: 12),
Spacer(),
ShimmerPlaceholder(width: 80, height: 12),
],
),
],
),
),
],
);
}

View File

@ -8,9 +8,11 @@ import 'package:didvan/views/home/new_statistic/stock/newStock_state.dart';
import 'package:didvan/views/home/new_statistic/stock/total_type3.dart';
import 'package:didvan/views/home/new_statistic/stock/total_type4.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/search_field.dart';
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/state_handlers/empty_result.dart';
import 'package:didvan/views/widgets/state_handlers/state_handler.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@ -71,10 +73,7 @@ class _NewStockState extends State<NewStock> {
@override
Widget build(BuildContext context) {
return StateHandler<NewStockState>(
onRetry: context.read<NewStockState>().init,
state: context.watch<NewStockState>(),
builder: (context, state) => Scaffold(
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,
elevation: 0.0,
@ -94,7 +93,7 @@ class _NewStockState extends State<NewStock> {
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: SearchField(
title: "بازار سرمایه",
value: state.lastSearch,
value: context.watch<NewStockState>().lastSearch,
onChanged: _onChanged,
focusNode: _focusNode,
),
@ -122,18 +121,30 @@ class _NewStockState extends State<NewStock> {
onToggle: (index) {
setState(() {
value = index!;
state.type = index + 1;
state.getStock(page: 1);
context.read<NewStockState>().type = index + 1;
context.read<NewStockState>().getStock(page: 1);
});
},
),
SizedBox(
height: MediaQuery.of(context).size.height / 48,
),
Expanded(
StateHandler<NewStockState>(
onRetry: context.read<NewStockState>().init,
state: context.watch<NewStockState>(),
emptyState: EmptyResult(
onNewSearch: () => _focusNode.requestFocus(),
),
enableEmptyState: context.watch<NewStockState>().contents.isEmpty,
placeholder: Column(
children: [
placeholder2,
placeholder2,
],
),
builder: (context, state) => Expanded(
child: ListView.builder(
controller: _scrollController,
//physics: const ClampingScrollPhysics(),
itemCount: state.length,
itemBuilder: (context, index) {
if (state.type == 1) {
@ -172,73 +183,94 @@ class _NewStockState extends State<NewStock> {
totalContent: state.totalContent_type3[index]);
}),
),
],
),
],
),
);
}
static Widget get placeholder => const DidvanCard(
static Widget get placeholder2 => const DidvanCard(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ShimmerPlaceholder(
height: 40,
width: 40,
ShimmerPlaceholder(height: 18, width: 400),
DidvanDivider(
verticalPadding: 8,
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
height: 40,
width: 40,
width: 100,
height: 18,
),
SizedBox(
height: 12,
),
ShimmerPlaceholder(
height: 40,
width: 40,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
height: 40,
width: 40,
),
ShimmerPlaceholder(
height: 40,
width: 40,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
height: 40,
width: 40,
),
ShimmerPlaceholder(
height: 40,
width: 40,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
height: 40,
width: 40,
),
ShimmerPlaceholder(
height: 40,
width: 40,
),
],
width: 100,
height: 18,
)
],
));
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
width: 100,
height: 18,
),
SizedBox(
height: 12,
),
ShimmerPlaceholder(
width: 100,
height: 18,
)
],
),
SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
width: 100,
height: 18,
),
SizedBox(
height: 12,
),
ShimmerPlaceholder(
width: 100,
height: 18,
)
],
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ShimmerPlaceholder(
width: 100,
height: 18,
),
SizedBox(
height: 12,
),
ShimmerPlaceholder(
width: 100,
height: 18,
)
],
),
],
),
);
}

View File

@ -59,7 +59,8 @@ class _NewStatisticOverviewCardState extends State<NewStatisticOverviewCard> {
'title': widget.statistic.title,
'marked': widget.statistic.marked,
}).then(
(value) => state.getGeneralStatContent(page: 1),
(value) =>
state.getGeneralStatContent(page: 1, id: state.cat),
);
}
},
@ -91,6 +92,11 @@ class _NewStatisticOverviewCardState extends State<NewStatisticOverviewCard> {
style: Theme.of(context).textTheme.bodyLarge,
),
const Spacer(),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (_hasDiff)
DidvanText(
'(${widget.statistic.data.d})',

View File

@ -17,9 +17,14 @@ class StatMenuItemType {
{required this.label, required this.asset, required this.id});
}
class NewStatisticCategories extends StatelessWidget {
class NewStatisticCategories extends StatefulWidget {
const NewStatisticCategories({super.key});
@override
State<NewStatisticCategories> createState() => _NewStatisticCategoriesState();
}
class _NewStatisticCategoriesState extends State<NewStatisticCategories> {
void _onTap(int id, String title, BuildContext context, BuildContext ctx) {
if (id != 6) {
Navigator.of(context)
@ -31,10 +36,8 @@ class NewStatisticCategories extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StateHandler<NewStatisticState>(
onRetry: () {},
state: context.watch<NewStatisticState>(),
builder: (context, state) => Wrap(
final state = context.read<NewStatisticState>();
return Wrap(
alignment: WrapAlignment.center,
children: state.statCat
.map(
@ -69,7 +72,6 @@ class NewStatisticCategories extends StatelessWidget {
),
)
.toList(),
),
);
}
}