diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-08-18 12:08:27 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-08-18 12:08:27 +0200 |
| commit | 1799d1324a9425e2f0f11c143c0c37cb042b05a7 (patch) | |
| tree | 77b9dc86e1aa2e768bb9f500709be0aeba4f0371 /lib/widgets | |
| parent | 349d704b67cf7d07bd8f8878735f98158a9a1756 (diff) | |
loading animations
Diffstat (limited to 'lib/widgets')
| -rw-r--r-- | lib/widgets/agenda_week.dart | 125 |
1 files changed, 83 insertions, 42 deletions
diff --git a/lib/widgets/agenda_week.dart b/lib/widgets/agenda_week.dart index a8f9350..fa3d100 100644 --- a/lib/widgets/agenda_week.dart +++ b/lib/widgets/agenda_week.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:loading_animation_widget/loading_animation_widget.dart'; import 'package:training_planner/events/RefreshWeekEvent.dart'; import 'package:training_planner/main.dart'; import 'package:training_planner/shift.dart'; @@ -26,35 +27,41 @@ class AgendaWeek extends StatefulWidget { } class _AgendaWeekState extends State<AgendaWeek> { - List<Widget> weekItems = []; + List<Widget>? weekItems; StreamSubscription? eventbusSubscription; - void updateItems() { + void updateItems() async { setState(() { - shiftProvider - .getShiftsForWeek(this.widget.mondayOfWeek) - .then((value) => setState(() { - weekItems = [ - AgendaWeekTitle( - weekNr: this.widget.weekNr, - mondayOfWeek: this.widget.mondayOfWeek, - isCurrentWeek: this.widget.isCurrentWeek), - Padding( - padding: const EdgeInsets.all(10), - ) - ]; - - for (var item in value) { - weekItems.add(new AgendaWeekItem( - shift: item, - updateParent: updateItems, - )); - } - - weekItems.add(Padding( - padding: const EdgeInsets.all(50), - )); - })); + weekItems = null; + }); + + var data = await shiftProvider.getShiftsForWeek(this.widget.mondayOfWeek); + if (!mounted) return; + setState(() { + weekItems = [ + AgendaWeekTitle( + weekNr: this.widget.weekNr, + mondayOfWeek: this.widget.mondayOfWeek, + isCurrentWeek: this.widget.isCurrentWeek), + Padding( + padding: const EdgeInsets.all(10), + ) + ]; + + for (var item in data) { + weekItems!.add(new AgendaWeekItem( + shift: item, + updateParent: updateItems, + )); + } + + if (data.isEmpty) { + weekItems!.add(Center(child: Text('Geen werktijden'))); + } + + weekItems!.add(Padding( + padding: const EdgeInsets.all(50), + )); }); } @@ -74,6 +81,55 @@ class _AgendaWeekState extends State<AgendaWeek> { super.dispose(); } + Widget getDataList() { + return SafeArea( + child: CustomScrollView( + physics: null, + slivers: [ + SliverPadding(padding: EdgeInsets.only(top: 20)), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return weekItems![index]; + }, + childCount: weekItems!.length, + )), + SliverPadding(padding: EdgeInsets.only(top: 20)), + ], + ), + ); + } + + Widget getLoadingScreen() { + return Column( + children: [ + Padding( + padding: const EdgeInsets.all(10), + ), + AgendaWeekTitle( + weekNr: this.widget.weekNr, + mondayOfWeek: this.widget.mondayOfWeek, + isCurrentWeek: this.widget.isCurrentWeek), + Padding( + padding: const EdgeInsets.all(10), + ), + LoadingAnimationWidget.flickr( + leftDotColor: Style.titleColor, + rightDotColor: Style.background, + size: MediaQuery.of(context).size.width / 4, + ) + ], + ); + } + + Widget getLoadingScreenOrDataList() { + if (weekItems != null) { + return getDataList(); + } else { + return getLoadingScreen(); + } + } + @override Widget build(BuildContext context) { return ShaderMask( @@ -96,22 +152,7 @@ class _AgendaWeekState extends State<AgendaWeek> { ).createShader(rect); }, blendMode: BlendMode.dstOut, - child: SafeArea( - child: CustomScrollView( - physics: null, - slivers: [ - SliverPadding(padding: EdgeInsets.only(top: 20)), - SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return weekItems[index]; - }, - childCount: weekItems.length, - )), - SliverPadding(padding: EdgeInsets.only(top: 20)), - ], - ), - ), + child: getLoadingScreenOrDataList(), ); } } |
