mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-09-25 09:03:36 +08:00
Example for Unit Test (#52)
This commit is contained in:
39
unit_testing/lib/screens/home_screen.dart
Normal file
39
unit_testing/lib/screens/home_screen.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:unit_testing/components/place_info_card.dart';
|
||||
import 'package:unit_testing/model/location.dart';
|
||||
|
||||
import '../helpers.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
@override
|
||||
_HomeScreenState createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Unit Test'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: TouristPlaces.getData(), // this functions calls API.
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final List<Location> data = snapshot.data;
|
||||
return ListView.builder(
|
||||
physics: BouncingScrollPhysics(),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (context, index) => PlaceInfo(
|
||||
data: data[index],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user