Skip to content
Snippets Groups Projects
Select Git revision
  • 9e691bb5d93dcbc5973c65204cd69e41bf639844
  • main default protected
  • release/1.1
  • encrypt_comments
  • mnemonic_dewif
  • authors_rules
  • 0.14
  • rtd
  • 1.2.1 protected
  • 1.2.0 protected
  • 1.1.1 protected
  • 1.1.0 protected
  • 1.0.0 protected
  • 1.0.0rc1 protected
  • 1.0.0rc0 protected
  • 1.0.0-rc protected
  • 0.62.0 protected
  • 0.61.0 protected
  • 0.60.1 protected
  • 0.58.1 protected
  • 0.60.0 protected
  • 0.58.0 protected
  • 0.57.0 protected
  • 0.56.0 protected
  • 0.55.1 protected
  • 0.55.0 protected
  • 0.54.3 protected
  • 0.54.2 protected
28 results

request_data_elasticsearch.py

Blame
  • 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);
          },
        );