use ab cache init show and show custom loading when ab not emtpy

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-08-11 15:27:50 +08:00
parent ea12eccc90
commit bea88f31e0
6 changed files with 160 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ import 'package:get/get.dart';
import '../../common.dart';
import 'dialog.dart';
import 'loading_dot_widget.dart';
import 'login.dart';
final hideAbTagsPanel = false.obs;
@@ -39,7 +40,7 @@ class _AddressBookState extends State<AddressBook> {
child: ElevatedButton(
onPressed: loginDialog, child: Text(translate("Login"))));
} else {
if (gFFI.abModel.abLoading.value) {
if (gFFI.abModel.abLoading.value && gFFI.abModel.emtpy) {
return const Center(
child: CircularProgressIndicator(),
);
@@ -47,9 +48,15 @@ class _AddressBookState extends State<AddressBook> {
if (gFFI.abModel.abError.isNotEmpty) {
return _buildShowError(gFFI.abModel.abError.value);
}
return isDesktop
? _buildAddressBookDesktop()
: _buildAddressBookMobile();
return Column(
children: [
_buildLoadingHavingPeers(),
Expanded(
child: isDesktop
? _buildAddressBookDesktop()
: _buildAddressBookMobile())
],
);
}
});
@@ -68,6 +75,22 @@ class _AddressBookState extends State<AddressBook> {
));
}
Widget _buildLoadingHavingPeers() {
double size = 15;
return Obx(() => Offstage(
offstage: !(gFFI.abModel.abLoading.value && !gFFI.abModel.emtpy),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: size,
child: Center(child: LoadingDotWidget(size: size)))
.marginSymmetric(vertical: 10)
],
),
));
}
Widget _buildAddressBookDesktop() {
return Row(
children: [

View File

@@ -0,0 +1,65 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class LoadingDotWidget extends StatefulWidget {
final int count;
final double size;
final int duration;
LoadingDotWidget(
{Key? key, required this.size, this.count = 3, this.duration = 200})
: super(key: key);
@override
State<LoadingDotWidget> createState() => _LoadingDotWidgetState();
}
class _LoadingDotWidgetState extends State<LoadingDotWidget> {
int counter = 0;
Timer? timer;
@override
void initState() {
super.initState();
startAnimation();
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
void startAnimation() {
timer = Timer.periodic(Duration(milliseconds: widget.duration), (timer) {
if (mounted) {
setState(() {
counter = (counter + 1) % widget.count;
});
}
});
}
@override
Widget build(BuildContext context) {
getChild(int index) {
return AnimatedContainer(
duration: Duration(milliseconds: widget.duration),
width: counter == index ? widget.size : widget.size / 2,
height: counter == index ? widget.size : widget.size / 2,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey,
),
).marginSymmetric(horizontal: widget.size);
}
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(widget.count, (e) => e)
.map((e) => getChild(e))
.toList()),
);
}
}

View File

@@ -987,7 +987,7 @@ class AddressBookPeerCard extends BasePeerCard {
@protected
@override
void _update() => gFFI.abModel.pullAb();
void _update() => gFFI.abModel.pullAb(quiet: true);
@protected
MenuEntryBase<String> _editTagAction(String id) {