Advertisement
multiarts

CategoryDetail

May 15th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.73 KB | None | 0 0
  1. class CategoryDetail extends StatefulWidget {
  2.   final Category category;
  3.  
  4.   CategoryDetail(this.category);
  5.  
  6.   @override
  7.   _CategoryDetailState createState() => _CategoryDetailState();
  8. }
  9.  
  10. class _CategoryDetailState extends State<CategoryDetail> {
  11.   final String pathImage = apiURLimg;
  12.   String id;
  13.   String nextPage = apiUrlClients;
  14.  
  15.   ScrollController _scrollController = ScrollController();
  16.   bool isLoading = false;
  17.  
  18.   List clients = List();
  19.   Dio dio = Dio();
  20.  
  21.   void _getMoreData() async {
  22.     print(apiUrlClients + "${widget.category.id}");
  23.     if (!isLoading) {
  24.       setState(() {
  25.         isLoading = true;
  26.       });
  27.  
  28.       final clientURL = apiUrlClients + "${widget.category.id}";
  29.       final response = await dio.get(clientURL);
  30.       List tempList = List();
  31.       nextPage = response.data['next_page_url'];
  32.  
  33.       for (int i = 0; i < response.data['data'].length; i++) {
  34.         tempList.add(response.data['data'][i]);
  35.       }
  36.  
  37.       setState(() {
  38.         isLoading = false;
  39.         clients.addAll(tempList);
  40.       });
  41.     }
  42.   }
  43.  
  44.   /* Future getData() async {
  45.     final res = await dio.get(apiURL+'${widget.category.id}');
  46.     data = json.decode(res.data);
  47.     clientData = data[''];
  48.     debugPrint(clientData.toString());
  49.   } */
  50.  
  51.   @override
  52.   void initState() {
  53.     this._getMoreData();
  54.     super.initState();
  55.     _scrollController.addListener(() {
  56.       if (_scrollController.position.pixels ==
  57.           _scrollController.position.maxScrollExtent) {
  58.         _getMoreData();
  59.       }
  60.     });
  61.   }
  62.  
  63.   @override
  64.   void dispose() {
  65.     _scrollController.dispose();
  66.     super.dispose();
  67.   }
  68.  
  69.   Widget _buildProgressIndicator() {
  70.     return new Padding(
  71.       padding: const EdgeInsets.all(8.0),
  72.       child: new Center(
  73.         child: new Opacity(
  74.           opacity: isLoading ? 1.0 : 00,
  75.           child: new CircularProgressIndicator(),
  76.         ),
  77.       ),
  78.     );
  79.   }
  80.  
  81.   @override
  82.   Widget build(BuildContext context) {
  83.     return Scaffold(
  84.       appBar: AppBar(
  85.         title: Text('${widget.category.name}'),
  86.       ),
  87.       body: _gridview(),
  88.       resizeToAvoidBottomPadding: false,
  89.     );
  90.   }
  91.  
  92.   _gridview() {
  93.     return ListView.builder(
  94.       /* gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  95.         crossAxisCount: 2,
  96.         crossAxisSpacing: 1,
  97.         childAspectRatio: 1.9,
  98.         mainAxisSpacing: 1), */
  99.       itemCount: clients.length + 1,
  100.       controller: _scrollController,
  101.       itemBuilder: (context, i) {
  102.         if (i == clients.length) return _buildProgressIndicator();
  103.         return GestureDetector(
  104.           onTap: () {},
  105.           child: Container(
  106.             height: 60,
  107.             decoration: BoxDecoration(
  108.               color: RED,
  109.             ),
  110.             child: Container(
  111.               decoration: BoxDecoration(
  112.                 gradient: LinearGradient(
  113.                   colors: [SEA_DEEP.withOpacity(.2), SEA_DEEP],
  114.                   begin: Alignment.topCenter,
  115.                   end: Alignment.bottomCenter,
  116.                 ),
  117.                 image: DecorationImage(
  118.                     image: NetworkImage("${clients[i]['image']}"),
  119.                     fit: BoxFit.cover),
  120.               ),
  121.               child: Column(
  122.                 mainAxisAlignment: MainAxisAlignment.center,
  123.                 children: <Widget>[
  124.                   Text(
  125.                     "${clients[i]['name']}".toUpperCase(),
  126.                     style: TextStyle(
  127.                         color: ICE, fontSize: 22, fontWeight: FontWeight.w700),
  128.                     softWrap: true,
  129.                     textAlign: TextAlign.center,
  130.                   ),
  131.                 ],
  132.               ),
  133.             ),
  134.           ),
  135.         );
  136.       },
  137.     );
  138.   }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement