SHARE
TWEET

Untitled

a guest Feb 27th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:briqueesperto/components/Cards/CustomCard.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_mobx/flutter_mobx.dart';
  4.  
  5. class CustomListView extends StatefulWidget {
  6.   final controller;
  7.   CustomListView(this.controller);
  8.  
  9.   @override
  10.   _CustomListViewState createState() => _CustomListViewState();
  11. }
  12.  
  13. class _CustomListViewState extends State<CustomListView> {
  14.   int posInicial = 0;
  15.   ScrollController _scrollController = new ScrollController();
  16.  
  17.   @override
  18.   void initState() {
  19.     super.initState();
  20.  
  21.     widget.controller.searchProducts(posInicial, context);
  22.  
  23.     _scrollController.addListener(() {
  24.       if (_scrollController.position.pixels ==
  25.           _scrollController.position.maxScrollExtent) {
  26.         posInicial = posInicial + 10;
  27.         widget.controller.searchProducts(posInicial, context);
  28.       }
  29.     });
  30.   }
  31.  
  32.   @override
  33.   Widget build(BuildContext context) {
  34.     return Scaffold(
  35.       body: Observer(
  36.         builder: (_) {
  37.           return widget.controller.produtos.length == null
  38.               ? Container()
  39.               : widget.controller.produtos.length == 0
  40.                   ? Container()
  41.                   : ListView.builder(
  42.                       controller: _scrollController,
  43.                       itemCount: widget.controller.produtos.length,
  44.                       itemBuilder: (context, index) {
  45.                         final item = widget.controller.produtos[index];
  46.                         return CustomCard(
  47.                           item: item,
  48.                         );
  49.                       },
  50.                     );
  51.         },
  52.       ),
  53.     );
  54.   }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top