added skeleton loading
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:game_tracker/presentation/widgets/full_width_button.dart';
|
import 'package:game_tracker/presentation/widgets/full_width_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/group_tile.dart';
|
import 'package:game_tracker/presentation/widgets/group_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
|
import 'package:skeletonizer/skeletonizer.dart';
|
||||||
|
|
||||||
class Group {
|
class Group {
|
||||||
final String id;
|
final String id;
|
||||||
@@ -29,7 +30,7 @@ class GroupsView extends StatefulWidget {
|
|||||||
|
|
||||||
class _GroupsViewState extends State<GroupsView> {
|
class _GroupsViewState extends State<GroupsView> {
|
||||||
Future<List<Group>> _getMockGroups() async {
|
Future<List<Group>> _getMockGroups() async {
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 4));
|
||||||
final player1 = Player(id: 'p1', name: 'Felix');
|
final player1 = Player(id: 'p1', name: 'Felix');
|
||||||
final player2 = Player(id: 'p2', name: 'Yannick');
|
final player2 = Player(id: 'p2', name: 'Yannick');
|
||||||
final player3 = Player(id: 'p3', name: 'Mathis');
|
final player3 = Player(id: 'p3', name: 'Mathis');
|
||||||
@@ -88,45 +89,73 @@ class _GroupsViewState extends State<GroupsView> {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final player = Player(id: 'p1', name: 'Felix');
|
||||||
|
late final List<Group> skeletonData = List.filled(
|
||||||
|
7,
|
||||||
|
Group(
|
||||||
|
id: 'g1',
|
||||||
|
name: 'Weekend Warriors',
|
||||||
|
members: [player, player, player, player],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
FutureBuilder(
|
FutureBuilder<List<Group>>(
|
||||||
future: _getMockGroups(),
|
future: _getMockGroups(),
|
||||||
builder:
|
builder:
|
||||||
(BuildContext context, AsyncSnapshot<List<Group>> snapshot) {
|
(BuildContext context, AsyncSnapshot<List<Group>> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.hasError) {
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
message: 'Data not yet available, show sceleton',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (snapshot.hasError) {
|
|
||||||
return const Center(
|
return const Center(
|
||||||
child: TopCenteredMessage(
|
child: TopCenteredMessage(
|
||||||
message: 'Error while loading group data.',
|
message: 'Error while loading group data.',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
}
|
||||||
|
if (snapshot.connectionState == ConnectionState.done &&
|
||||||
|
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
||||||
return const Center(
|
return const Center(
|
||||||
child: TopCenteredMessage(
|
child: TopCenteredMessage(
|
||||||
message: 'No groups created yet.',
|
message: 'No groups created yet.',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//return Center(child: Text('whatever'));
|
final bool isLoading =
|
||||||
//return GroupTile(group: snapshot.data![0]);
|
snapshot.connectionState == ConnectionState.waiting;
|
||||||
return ListView.builder(
|
final List<Group> groups = isLoading
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
? skeletonData
|
||||||
itemCount: snapshot.data!.length,
|
: (snapshot.data ?? []);
|
||||||
itemBuilder: (BuildContext context, int index) {
|
return Skeletonizer(
|
||||||
return GroupTile(group: snapshot.data![index]);
|
effect: PulseEffect(
|
||||||
},
|
from: Colors.grey[100]!,
|
||||||
|
to: Colors.grey[400]!,
|
||||||
|
duration: const Duration(milliseconds: 800),
|
||||||
|
),
|
||||||
|
enabled: isLoading,
|
||||||
|
enableSwitchAnimation: true,
|
||||||
|
switchAnimationConfig: const SwitchAnimationConfig(
|
||||||
|
duration: Duration(milliseconds: 200),
|
||||||
|
switchInCurve: Curves.linear,
|
||||||
|
switchOutCurve: Curves.linear,
|
||||||
|
transitionBuilder:
|
||||||
|
AnimatedSwitcher.defaultTransitionBuilder,
|
||||||
|
layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
|
itemCount: groups.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return GroupTile(group: groups[index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Dein Button bleibt wie gehabt
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 16,
|
bottom: 16,
|
||||||
right: 16,
|
right: 16,
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class GroupTile extends StatelessWidget {
|
|||||||
horizontal: 10,
|
horizontal: 10,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black26,
|
color: Colors.black38,
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|||||||
Reference in New Issue
Block a user