update
This commit is contained in:
parent
8f3ca96bb7
commit
2ad472f055
@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' show get;
|
||||
|
||||
import 'models/image_model.dart';
|
||||
import 'dart:convert';
|
||||
import 'widgets/image_list.dart';
|
||||
|
||||
class App extends StatefulWidget {
|
||||
createState() {
|
||||
@ -14,11 +16,23 @@ class App extends StatefulWidget {
|
||||
|
||||
class AppState extends State<App> {
|
||||
int counter = 0;
|
||||
List<ImageModel> images = [];
|
||||
|
||||
void fetchImage() async {
|
||||
counter += 1;
|
||||
var response = await get('https://jsonplaceholder.typicode.com/photos/$counter');
|
||||
var response =
|
||||
await get('https://jsonplaceholder.typicode.com/photos/$counter');
|
||||
print(response.body);
|
||||
|
||||
var imageModel = ImageModel.fromJson(json.decode(response.body));
|
||||
|
||||
print(imageModel);
|
||||
|
||||
setState(() {
|
||||
images.add(imageModel);
|
||||
});
|
||||
}
|
||||
|
||||
// must define a 'build' method that returns
|
||||
// the widgets that *this* widget will show
|
||||
|
||||
@ -28,7 +42,7 @@ class AppState extends State<App> {
|
||||
appBar: AppBar(
|
||||
title: Text('Lets see some images'),
|
||||
),
|
||||
body: Text('$counter'),
|
||||
body: ImageList(images),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: fetchImage,
|
||||
child: Icon(Icons.add),
|
||||
|
8
lib/src/widgets/image_list.dart
Normal file
8
lib/src/widgets/image_list.dart
Normal file
@ -0,0 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/image_model.dart';
|
||||
|
||||
class ImageList extends StatelessWidget {
|
||||
final List<ImageModel> images;
|
||||
|
||||
ImageList(this.images);
|
||||
}
|
14
pubspec.lock
14
pubspec.lock
@ -74,6 +74,20 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.0+4"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
image:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -23,6 +23,7 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
http: ^0.12.0+4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user