From 6df9060a7243fcb609b8dda52a39a7a9583af232 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 14 Sep 2020 23:58:59 +0200 Subject: [PATCH] loading animation after 500ms --- lib/pages/communities_tab.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pages/communities_tab.dart b/lib/pages/communities_tab.dart index 2e2f552..d97ca7f 100644 --- a/lib/pages/communities_tab.dart +++ b/lib/pages/communities_tab.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -210,10 +212,13 @@ class _CommunitySubscribeToggle extends HookWidget { var theme = Theme.of(context); var subed = useState(true); var loading = useState(false); - // TODO: load animation after 500ms + return InkWell( onTap: () async { - loading.value = true; + // load animation only after 500ms + var timerHandle = + Timer(Duration(milliseconds: 500), () => loading.value = true); + try { await LemmyApi(instanceUrl).v1.followCommunity( communityId: communityId, @@ -223,6 +228,7 @@ class _CommunitySubscribeToggle extends HookWidget { .defaultTokenFor(instanceUrl) .raw, ); + timerHandle.cancel(); subed.value = !subed.value; } on Exception catch (err) { Scaffold.of(context).showSnackBar(SnackBar(