SHARE
TWEET

Untitled

a guest Jan 24th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:poem_app/models/poem.dart';
  3. import 'package:poem_app/services/api.dart';
  4. import 'package:poem_app/components/cards/CardItem.dart';
  5.  
  6. class FavoriteScreen extends StatefulWidget {
  7.   @override
  8.   FavoriteState createState() => FavoriteState();
  9. }
  10.  
  11. class FavoriteState extends State<FavoriteScreen> {
  12.   final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
  13.       new GlobalKey<RefreshIndicatorState>();
  14.   final apiService = ApiService.getInstance();
  15.   var poemsList;
  16.  
  17.   void getPoems() {
  18.     var _poems = apiService.getPublicPoems();
  19.     setState(() {
  20.       _poems.then((result) {
  21.         setState(() {
  22.           poemsList = result;
  23.         });
  24.       });
  25.     });
  26.   }
  27.  
  28.   @override
  29.   void initState() {
  30.     // TODO: implement initState
  31.     WidgetsBinding.instance
  32.         .addPostFrameCallback((_) => _refreshIndicatorKey.currentState.show());
  33.  
  34.     super.initState();
  35.   }
  36.  
  37.   @override
  38.   Widget build(BuildContext context) {
  39.     return FutureBuilder<PoemResponse>(
  40.       future: apiService.getPublicPoems(),
  41.       builder: (context, data) {
  42.         return Container(
  43.             child: RefreshIndicator(
  44.           key: _refreshIndicatorKey,
  45.           onRefresh: () async {
  46.           },
  47.           child: ListView.builder(
  48.             itemCount: data.data.poems.length,
  49.             itemBuilder: (BuildContext context, int index) {
  50.               return CardItem(
  51.                 color: Colors.white,
  52.                 verse: data.data.poems[index],
  53.                 onTap: () {},
  54.               );
  55.             },
  56.           ),
  57.         ));
  58.       },
  59.     );
  60.   }
  61. }
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