update
This commit is contained in:
parent
8f3ca96bb7
commit
2ad472f055
@ -1,6 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' show get;
|
import 'package:http/http.dart' show get;
|
||||||
|
import 'models/image_model.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'widgets/image_list.dart';
|
||||||
|
|
||||||
class App extends StatefulWidget {
|
class App extends StatefulWidget {
|
||||||
createState() {
|
createState() {
|
||||||
@ -14,11 +16,23 @@ class App extends StatefulWidget {
|
|||||||
|
|
||||||
class AppState extends State<App> {
|
class AppState extends State<App> {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
List<ImageModel> images = [];
|
||||||
|
|
||||||
void fetchImage() async {
|
void fetchImage() async {
|
||||||
counter += 1;
|
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
|
// must define a 'build' method that returns
|
||||||
// the widgets that *this* widget will show
|
// the widgets that *this* widget will show
|
||||||
|
|
||||||
@ -28,7 +42,7 @@ class AppState extends State<App> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Lets see some images'),
|
title: Text('Lets see some images'),
|
||||||
),
|
),
|
||||||
body: Text('$counter'),
|
body: ImageList(images),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: fetchImage,
|
onPressed: fetchImage,
|
||||||
child: Icon(Icons.add),
|
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
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
image:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -23,6 +23,7 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^0.1.2
|
cupertino_icons: ^0.1.2
|
||||||
|
http: ^0.12.0+4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user