add providers per page
show only 10 packages new page for all packages
This commit is contained in:
		@@ -2,7 +2,6 @@ import 'dart:async';
 | 
			
		||||
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:provider/provider.dart';
 | 
			
		||||
import 'package:visibility_detector/visibility_detector.dart';
 | 
			
		||||
 | 
			
		||||
import '../../providers/BaseProvider.dart';
 | 
			
		||||
 | 
			
		||||
@@ -26,7 +25,6 @@ class APIBuilder<T extends BaseProvider, K, DTO> extends StatefulWidget {
 | 
			
		||||
class _APIBuilderState<T extends BaseProvider, K, DTO>
 | 
			
		||||
    extends State<APIBuilder<T, K, DTO>> {
 | 
			
		||||
  Timer? timer;
 | 
			
		||||
  bool visible = true;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
@@ -35,10 +33,8 @@ class _APIBuilderState<T extends BaseProvider, K, DTO>
 | 
			
		||||
 | 
			
		||||
    if (widget.interval != null) {
 | 
			
		||||
      timer = Timer.periodic(widget.interval!, (Timer t) {
 | 
			
		||||
        if (visible) {
 | 
			
		||||
          Provider.of<T>(context, listen: false)
 | 
			
		||||
              .refresh(context, dto: widget.dto);
 | 
			
		||||
        }
 | 
			
		||||
        Provider.of<T>(context, listen: false)
 | 
			
		||||
            .refresh(context, dto: widget.dto);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -53,30 +49,15 @@ class _APIBuilderState<T extends BaseProvider, K, DTO>
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    final Future<K> fut = Provider.of<T>(context).data as Future<K>;
 | 
			
		||||
 | 
			
		||||
    return VisibilityDetector(
 | 
			
		||||
      key: widget.key ?? const Key("APIBuilder"),
 | 
			
		||||
      onVisibilityChanged: (visibilityInfo) {
 | 
			
		||||
        var visiblePercentage = visibilityInfo.visibleFraction * 100;
 | 
			
		||||
 | 
			
		||||
        if (mounted) {
 | 
			
		||||
          setState(() {
 | 
			
		||||
            visible = visiblePercentage != 0;
 | 
			
		||||
          });
 | 
			
		||||
    return FutureBuilder<K>(
 | 
			
		||||
      future: fut,
 | 
			
		||||
      builder: (context, snapshot) {
 | 
			
		||||
        if (snapshot.hasData) {
 | 
			
		||||
          return widget.onData(snapshot.data!);
 | 
			
		||||
        } else {
 | 
			
		||||
          return widget.onLoad();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        debugPrint(
 | 
			
		||||
            'Widget ${visibilityInfo.key} is ${visiblePercentage}% visible');
 | 
			
		||||
      },
 | 
			
		||||
      child: FutureBuilder<K>(
 | 
			
		||||
        future: fut,
 | 
			
		||||
        builder: (context, snapshot) {
 | 
			
		||||
          if (snapshot.hasData) {
 | 
			
		||||
            return widget.onData(snapshot.data!);
 | 
			
		||||
          } else {
 | 
			
		||||
            return widget.onLoad();
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user