Select Git revision
runtime-calls.md
Forked from
nodes / rust / Duniter v2S
Source project has a limited visibility.
-
Hugo Trentesaux authored
* review: disabled calls description * remote to_vec * fix broken markdown * run `xtask gen-calls-doc` * use tera templates to generate runtime calls doc
Hugo Trentesaux authored* review: disabled calls description * remote to_vec * fix broken markdown * run `xtask gen-calls-doc` * use tera templates to generate runtime calls doc
certifications.dart 2.55 KiB
import 'package:flutter/material.dart';
import 'package:gecko/models/scale_functions.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:provider/provider.dart';
// Add a class to store certification data
class CertificationData {
final int receivedCount;
final int sentCount;
CertificationData({required this.receivedCount, required this.sentCount});
bool equals(CertificationData? other) {
if (other == null) return false;
return receivedCount == other.receivedCount && sentCount == other.sentCount;
}
}
class Certifications extends StatefulWidget {
const Certifications({super.key, required this.address, required this.size, this.color = Colors.black});
final String address;
final double size;
final Color color;
@override
State<Certifications> createState() => _CertificationsState();
}
class _CertificationsState extends State<Certifications> {
bool _isLoading = false;
Future<void> _checkNetworkData(SubstrateSdk sdk) async {
if (_isLoading) return;
_isLoading = true;
try {
final networkData = await sdk.getCertsCounter(widget.address);
if (!mounted) return;
final cachedData = sdk.certsCounterCache[widget.address];
if (cachedData == null || !cachedData.equals(networkData)) {
sdk.certsCounterCache[widget.address] = networkData;
setState(() {});
}
} finally {
_isLoading = false;
}
}
@override
Widget build(BuildContext context) {
return Consumer<SubstrateSdk>(
builder: (context, sdk, _) {
// Display cached data immediately if available
final cachedCerts = sdk.certsCounterCache[widget.address];
// Check network data in the background
if (!_isLoading) {
Future.microtask(() => _checkNetworkData(sdk));
}
// If no cached data, show nothing while waiting
if (cachedCerts == null) {
return const SizedBox.shrink();
}
// Display cached data
return _buildContent(cachedCerts.receivedCount, cachedCerts.sentCount);
},
);