fix(bugs): prevent redundant API calls on PieChart interaction in DeviceManagerPage

This commit is contained in:
anhtunz
2025-01-13 10:11:26 +07:00
parent a17831d0ac
commit 408c92d843
5 changed files with 44 additions and 52 deletions

View File

@@ -3,7 +3,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../../product/extention/context_extention.dart';
import '../../product/services/language_services.dart';
import '../../product/constant/enums/app_theme_enums.dart';
import '../../bloc/bell_bloc.dart';
import '../../product/base/bloc/base_bloc.dart';
import '../../product/services/api_services.dart';

View File

@@ -30,6 +30,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
List<Device> devices = [];
Timer? getAllDevicesTimer;
List<Widget> tags = [];
int tagIndex = -2;
@override
void initState() {
super.initState();
@@ -38,7 +39,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
const duration = Duration(seconds: 10);
getAllDevicesTimer = Timer.periodic(
duration,
(Timer t) => devicesManagerBloc.getDeviceByState(-2),
(Timer t) => devicesManagerBloc.getDeviceByState(tagIndex),
);
}
@@ -65,7 +66,10 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
.getDeviceByState(tagSnapshot.data?[0] ?? -2);
return const Center(child: CircularProgressIndicator());
} else {
if (tagSnapshot.data!.isNotEmpty) {}
if (tagSnapshot.data!.isNotEmpty) {
tagIndex = tagSnapshot.data![0];
devicesManagerBloc.sinkTagStates.add([tagIndex]);
}
return SingleChildScrollView(
child: Column(
children: [
@@ -154,7 +158,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
// log('Chuyen page: $pageIndex');
},
rowsPerPage:
(allDeviceSnapshot.data?.length ?? 0) < 6
(allDeviceSnapshot.data?.length ?? 1) < 6
? (allDeviceSnapshot.data?.length ??
0)
: 5,

View File

@@ -52,8 +52,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
backgroundColor: Theme.of(context).focusColor,
radius: 70,
child: CircleAvatar(
backgroundColor: Theme.of(context).highlightColor,
radius: 60,
child: CircleAvatar(
radius: 50,
@@ -61,7 +63,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
getAvatarContent(
userSnapshot.data?.username ?? ""),
style: const TextStyle(
fontSize: 35, fontWeight: FontWeight.bold),
fontSize: 35,
fontWeight: FontWeight.bold,
),
),
),
),
@@ -121,6 +125,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
},
child: Card(
color: Theme.of(context).colorScheme.onInverseSurface,
margin: const EdgeInsets.only(left: 35, right: 35, bottom: 10),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
child: ListTile(