Advertisement
joaopaulofcc

Untitled

Nov 18th, 2020
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.92 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'controls/databaseClient.dart';
  4. import 'models/dog.dart';
  5.  
  6. void main() => runApp(MyApp());
  7.  
  8. class MyApp extends StatelessWidget {
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return MaterialApp(
  12.       theme: ThemeData(
  13.         primarySwatch: Colors.cyan,
  14.       ),
  15.       home: DogPage(),
  16.     );
  17.   }
  18. }
  19.  
  20. class DogPage extends StatefulWidget {
  21.   @override
  22.   _DogPageState createState() => _DogPageState();
  23. }
  24.  
  25. class _DogPageState extends State<DogPage> {
  26.   final GlobalKey<FormState> _formStateKey = GlobalKey<FormState>();
  27.  
  28.   Future<List<Dog>> dogs;
  29.   int _dogId;
  30.   String _dogName;
  31.   int _dogAge;
  32.   bool isUpdate = false;
  33.   int dogIdForUpdate;
  34.   DatabaseClient db;
  35.  
  36.   final _dogIdController = TextEditingController();
  37.   final _dogNameController = TextEditingController();
  38.   final _dogAgeController = TextEditingController();
  39.  
  40.   @override
  41.   void initState() {
  42.     super.initState();
  43.     db = DatabaseClient();
  44.     openDatabase();
  45.   }
  46.  
  47.   openDatabase() async {
  48.     await db.open();
  49.     refreshDogList();
  50.   }
  51.  
  52.   refreshDogList() {
  53.     setState(() {
  54.       dogs = db.getDogs();
  55.     });
  56.   }
  57.  
  58.   @override
  59.   Widget build(BuildContext context) {
  60.     return Scaffold(
  61.       // Cria AppBar
  62.       appBar: AppBar(
  63.         title: Text('App Dog'),
  64.       ),
  65.  
  66.       body: Column(
  67.         children: <Widget>[
  68.           Form(
  69.             key: _formStateKey,
  70.             autovalidate: true,
  71.             child: Column(
  72.               children: <Widget>[
  73.                 Padding(
  74.                   padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
  75.                   child: TextFormField(
  76.                     validator: (value) {
  77.                       if (value.isEmpty) {
  78.                         return 'Por favor insira o Id do cachorro';
  79.                       }
  80.                       if (value.trim() == "")
  81.                         return "Somente espaço não é válido!";
  82.                       return null;
  83.                     },
  84.                     onSaved: (value) {
  85.                       _dogId = int.parse(value);
  86.                     },
  87.                     controller: _dogIdController,
  88.                     keyboardType: TextInputType.number,
  89.                     decoration: InputDecoration(
  90.                         focusedBorder: new UnderlineInputBorder(
  91.                             borderSide: new BorderSide(
  92.                                 color: Colors.cyan,
  93.                                 width: 2,
  94.                                 style: BorderStyle.solid)),
  95.                         labelText: "Id do cachorro",
  96.                         icon: Icon(
  97.                           Icons.vpn_key,
  98.                           color: Colors.cyan,
  99.                         ),
  100.                         fillColor: Colors.white,
  101.                         labelStyle: TextStyle(
  102.                           color: Colors.cyan,
  103.                         )),
  104.                   ),
  105.                 ),
  106.                 Padding(
  107.                   padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
  108.                   child: TextFormField(
  109.                     validator: (value) {
  110.                       if (value.isEmpty) {
  111.                         return 'Por favor insira o nome do cachorro';
  112.                       }
  113.                       if (value.trim() == "")
  114.                         return "Somente espaço não é válido!";
  115.                       return null;
  116.                     },
  117.                     onSaved: (value) {
  118.                       _dogName = value;
  119.                     },
  120.                     controller: _dogNameController,
  121.                     decoration: InputDecoration(
  122.                         focusedBorder: new UnderlineInputBorder(
  123.                             borderSide: new BorderSide(
  124.                                 color: Colors.cyan,
  125.                                 width: 2,
  126.                                 style: BorderStyle.solid)),
  127.                         labelText: "Nome do cachorro",
  128.                         icon: Icon(
  129.                           Icons.pets,
  130.                           color: Colors.cyan,
  131.                         ),
  132.                         fillColor: Colors.white,
  133.                         labelStyle: TextStyle(
  134.                           color: Colors.cyan,
  135.                         )),
  136.                   ),
  137.                 ),
  138.                 Padding(
  139.                   padding: EdgeInsets.only(left: 10, right: 10, bottom: 10),
  140.                   child: TextFormField(
  141.                     validator: (value) {
  142.                       if (value.isEmpty) {
  143.                         return 'Por favor insira a idade do cachorro';
  144.                       }
  145.                       if (value.trim() == "")
  146.                         return "Somente espaço não é válido!";
  147.                       return null;
  148.                     },
  149.                     onSaved: (value) {
  150.                       _dogAge = int.parse(value);
  151.                     },
  152.                     controller: _dogAgeController,
  153.                     keyboardType: TextInputType.number,
  154.                     decoration: InputDecoration(
  155.                         focusedBorder: new UnderlineInputBorder(
  156.                             borderSide: new BorderSide(
  157.                                 color: Colors.cyan,
  158.                                 width: 2,
  159.                                 style: BorderStyle.solid)),
  160.                         labelText: "Idade do cachorro",
  161.                         icon: Icon(
  162.                           Icons.calendar_today,
  163.                           color: Colors.cyan,
  164.                         ),
  165.                         fillColor: Colors.white,
  166.                         labelStyle: TextStyle(
  167.                           color: Colors.cyan,
  168.                         )),
  169.                   ),
  170.                 ),
  171.               ],
  172.             ),
  173.           ),
  174.         ],
  175.       ),
  176.     );
  177.   }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement