loading animation after 500ms
This commit is contained in:
parent
6dac4ac72c
commit
6df9060a72
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
@ -210,10 +212,13 @@ class _CommunitySubscribeToggle extends HookWidget {
|
||||||
var theme = Theme.of(context);
|
var theme = Theme.of(context);
|
||||||
var subed = useState(true);
|
var subed = useState(true);
|
||||||
var loading = useState(false);
|
var loading = useState(false);
|
||||||
// TODO: load animation after 500ms
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
loading.value = true;
|
// load animation only after 500ms
|
||||||
|
var timerHandle =
|
||||||
|
Timer(Duration(milliseconds: 500), () => loading.value = true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await LemmyApi(instanceUrl).v1.followCommunity(
|
await LemmyApi(instanceUrl).v1.followCommunity(
|
||||||
communityId: communityId,
|
communityId: communityId,
|
||||||
|
@ -223,6 +228,7 @@ class _CommunitySubscribeToggle extends HookWidget {
|
||||||
.defaultTokenFor(instanceUrl)
|
.defaultTokenFor(instanceUrl)
|
||||||
.raw,
|
.raw,
|
||||||
);
|
);
|
||||||
|
timerHandle.cancel();
|
||||||
subed.value = !subed.value;
|
subed.value = !subed.value;
|
||||||
} on Exception catch (err) {
|
} on Exception catch (err) {
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
Scaffold.of(context).showSnackBar(SnackBar(
|
||||||
|
|
Loading…
Reference in New Issue