Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter/widgets.dart';
- import 'controls/databaseClient.dart';
- import 'models/dog.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- theme: ThemeData(
- primarySwatch: Colors.cyan,
- ),
- home: DogPage(),
- );
- }
- }
- class DogPage extends StatefulWidget {
- @override
- _DogPageState createState() => _DogPageState();
- }
- class _DogPageState extends State<DogPage> {
- final GlobalKey<FormState> _formStateKey = GlobalKey<FormState>();
- Future<List<Dog>> dogs;
- int _dogId;
- String _dogName;
- int _dogAge;
- bool isUpdate = false;
- int dogIdForUpdate;
- DatabaseClient db;
- final _dogIdController = TextEditingController();
- final _dogNameController = TextEditingController();
- final _dogAgeController = TextEditingController();
- @override
- void initState() {
- super.initState();
- db = DatabaseClient();
- openDatabase();
- }
- openDatabase() async {
- await db.open();
- refreshDogList();
- }
- refreshDogList() {
- setState(() {
- dogs = db.getDogs();
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- // Cria AppBar
- appBar: AppBar(
- title: Text('App Dog'),
- ),
- body: Column(
- children: <Widget>[
- Form(
- key: _formStateKey,
- autovalidate: true,
- child: Column(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
- child: TextFormField(
- validator: (value) {
- if (value.isEmpty) {
- return 'Por favor insira o Id do cachorro';
- }
- if (value.trim() == "")
- return "Somente espaço não é válido!";
- return null;
- },
- onSaved: (value) {
- _dogId = int.parse(value);
- },
- controller: _dogIdController,
- keyboardType: TextInputType.number,
- decoration: InputDecoration(
- focusedBorder: new UnderlineInputBorder(
- borderSide: new BorderSide(
- color: Colors.cyan,
- width: 2,
- style: BorderStyle.solid)),
- labelText: "Id do cachorro",
- icon: Icon(
- Icons.vpn_key,
- color: Colors.cyan,
- ),
- fillColor: Colors.white,
- labelStyle: TextStyle(
- color: Colors.cyan,
- )),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
- child: TextFormField(
- validator: (value) {
- if (value.isEmpty) {
- return 'Por favor insira o nome do cachorro';
- }
- if (value.trim() == "")
- return "Somente espaço não é válido!";
- return null;
- },
- onSaved: (value) {
- _dogName = value;
- },
- controller: _dogNameController,
- decoration: InputDecoration(
- focusedBorder: new UnderlineInputBorder(
- borderSide: new BorderSide(
- color: Colors.cyan,
- width: 2,
- style: BorderStyle.solid)),
- labelText: "Nome do cachorro",
- icon: Icon(
- Icons.pets,
- color: Colors.cyan,
- ),
- fillColor: Colors.white,
- labelStyle: TextStyle(
- color: Colors.cyan,
- )),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
- child: TextFormField(
- validator: (value) {
- if (value.isEmpty) {
- return 'Por favor insira a idade do cachorro';
- }
- if (value.trim() == "")
- return "Somente espaço não é válido!";
- return null;
- },
- onSaved: (value) {
- _dogAge = int.parse(value);
- },
- controller: _dogAgeController,
- keyboardType: TextInputType.number,
- decoration: InputDecoration(
- focusedBorder: new UnderlineInputBorder(
- borderSide: new BorderSide(
- color: Colors.cyan,
- width: 2,
- style: BorderStyle.solid)),
- labelText: "Idade do cachorro",
- icon: Icon(
- Icons.calendar_today,
- color: Colors.cyan,
- ),
- fillColor: Colors.white,
- labelStyle: TextStyle(
- color: Colors.cyan,
- )),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement