mirrored_repositories/Flutter_ListView_API/lib
import 'package:flutter/material.dart';
import 'package:http/http.dart' show get;
import 'dart:convert';
import './models/image_model.dart';
import 'widgets/image_list.dart';

class App extends StatefulWidget {
  createState() {
    return AppState();
  }
}

class AppState extends State<App>  {
  int counter = 0;
  List<ImageModel> images = [];

  void _fetchImage () async {
    counter ++;
    var response = await get('http://jsonplaceholder.typicode.com/photos/$counter');
    var imageModel = ImageModel.fromJson(json.decode(response.body));

    setState(() {
      images.add(imageModel);
    });
    
  }

  Widget build(context) {
    return MaterialApp(
      home: Scaffold(
        body: ImageList(images),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: _fetchImage,
        ),
        appBar: AppBar(
          title: Text('Let´s see some images'),
        ),
      ),
    );
  }
}

