loading animation after 500ms

This commit is contained in:
shilangyu 2020-09-14 23:58:59 +02:00
parent 6dac4ac72c
commit 6df9060a72
1 changed files with 8 additions and 2 deletions

View File

@ -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(