Example for Unit Test (#52)

This commit is contained in:
Miten Gajjar
2020-07-06 00:12:20 +05:30
committed by GitHub
parent 07b7411e54
commit 389623e159
75 changed files with 1723 additions and 0 deletions

View 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());
}
},
),
);
}
}

View File

@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:unit_testing/helpers.dart';
class SignInScreen extends StatefulWidget {
@override
_SignInScreenState createState() => _SignInScreenState();
}
class _SignInScreenState extends State<SignInScreen> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Material(
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Form(
key: _formKey,
child: Column(
children: [
Icon(
Icons.account_circle,
size: 200,
),
SizedBox(
height: 50,
),
TextFormField(
validator: (value) => FormValidator.validateEmail(value),
decoration: InputDecoration(
hintText: "Email",
),
),
SizedBox(
height: 50,
),
TextFormField(
validator: (value) => FormValidator.validatePassword(value),
decoration: InputDecoration(
hintText: "Password",
),
),
SizedBox(
height: 50,
),
RaisedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
Navigator.of(context).pushReplacementNamed('/homeScreen');
}
},
child: Text('Sign In'),
)
],
),
),
),
);
}
}