Added pull to refresh clients

This commit is contained in:
Juan Gilsanz Polo 2022-10-09 01:20:38 +02:00
parent e8d3e14245
commit 5fa174ffc5

View file

@ -43,15 +43,17 @@ class _ClientsListState extends State<ClientsList> {
isVisible = true; isVisible = true;
widget.scrollController.addListener(() { widget.scrollController.addListener(() {
if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) { if (mounted) {
if (mounted && isVisible == true) { if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) {
setState(() => isVisible = false); if (mounted && isVisible == true) {
setState(() => isVisible = false);
}
} }
} else {
else { if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) {
if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) { if (mounted && isVisible == false) {
if (mounted && isVisible == false) { setState(() => isVisible = true);
setState(() => isVisible = true); }
} }
} }
} }
@ -232,69 +234,72 @@ class _ClientsListState extends State<ClientsList> {
case 1: case 1:
return Stack( return Stack(
children: [ children: [
Column( RefreshIndicator(
mainAxisSize: MainAxisSize.max, onRefresh: widget.fetchClients,
children: [ child: Column(
Padding( mainAxisSize: MainAxisSize.max,
padding: const EdgeInsets.all(10), children: [
child: Card( Padding(
child: Padding( padding: const EdgeInsets.all(10),
padding: const EdgeInsets.all(20), child: Card(
child: Row( child: Padding(
children: [ padding: const EdgeInsets.all(20),
const Icon(Icons.info_rounded), child: Row(
const SizedBox(width: 20), children: [
SizedBox( const Icon(Icons.info_rounded),
width: MediaQuery.of(context).size.width-112, const SizedBox(width: 20),
child: Text(description()), SizedBox(
) width: MediaQuery.of(context).size.width-112,
], child: Text(description()),
)
],
),
), ),
), ),
), ),
), if (widget.data.isNotEmpty) Expanded(
if (widget.data.isNotEmpty) Expanded( child: ListView.builder(
child: ListView.builder( padding: const EdgeInsets.only(top: 0),
padding: const EdgeInsets.only(top: 0), itemCount: widget.data.length,
itemCount: widget.data.length, itemBuilder: (context, index) => ListTile(
itemBuilder: (context, index) => ListTile( title: Text(widget.data[index]),
title: Text(widget.data[index]), trailing: IconButton(
trailing: IconButton( onPressed: () => {
onPressed: () => { showDialog(
showDialog( context: context,
context: context, builder: (context) => RemoveClientModal(
builder: (context) => RemoveClientModal( onConfirm: () => confirmRemoveItem(widget.data[index], widget.type),
onConfirm: () => confirmRemoveItem(widget.data[index], widget.type), )
) )
) },
}, icon: const Icon(Icons.delete_rounded)
icon: const Icon(Icons.delete_rounded)
),
)
),
),
if (widget.data.isEmpty) Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
noItems(),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 24,
color: Colors.grey
), ),
),
const SizedBox(height: 30),
TextButton.icon(
onPressed: widget.fetchClients,
icon: const Icon(Icons.refresh_rounded),
label: Text(AppLocalizations.of(context)!.refresh),
) )
], ),
), ),
), if (widget.data.isEmpty) Expanded(
], child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
noItems(),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 24,
color: Colors.grey
),
),
const SizedBox(height: 30),
TextButton.icon(
onPressed: widget.fetchClients,
icon: const Icon(Icons.refresh_rounded),
label: Text(AppLocalizations.of(context)!.refresh),
)
],
),
),
],
),
), ),
AnimatedPositioned( AnimatedPositioned(
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),