Skip to content

Commit

Permalink
34 - Armazenando Informações no Objeto Ad
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhciolfi committed Mar 12, 2020
1 parent 251bdc5 commit a024a5d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
17 changes: 17 additions & 0 deletions models/ad.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:xlo/models/address.dart';

class Ad {

List<dynamic> images;
String title;
String description;
Address address;
num price;
bool hidePhone;

@override
String toString() {
return '$images, $title, $description, $address, $price, $hidePhone';
}

}
19 changes: 12 additions & 7 deletions screens/create/create_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
import 'package:xlo/api/api_postalcode.dart';
import 'package:xlo/common/cep_field.dart';
import 'package:xlo/common/custom_drawer/custom_drawer.dart';
import 'package:xlo/models/ad.dart';
import 'package:xlo/screens/create/widgets/hide_phone_widget.dart';
import 'package:xlo/screens/create/widgets/images_field.dart';

Expand All @@ -16,6 +17,8 @@ class _CreateScreenState extends State<CreateScreen> {

final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

Ad ad = Ad();

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -30,7 +33,7 @@ class _CreateScreenState extends State<CreateScreen> {
children: <Widget>[
ImagesField(
onSaved: (images){

ad.images = images;
},
initialValue: [],
),
Expand All @@ -49,7 +52,7 @@ class _CreateScreenState extends State<CreateScreen> {
return null;
},
onSaved: (t) {

ad.title = t;
},
),
TextFormField(
Expand All @@ -70,7 +73,7 @@ class _CreateScreenState extends State<CreateScreen> {
return null;
},
onSaved: (d) {

ad.description = d;
},
),
CepField(
Expand All @@ -84,7 +87,7 @@ class _CreateScreenState extends State<CreateScreen> {
contentPadding: const EdgeInsets.fromLTRB(16, 10, 12, 10),
),
onSaved: (a) {
print(a);
ad.address = a;
},
),
TextFormField(
Expand All @@ -111,13 +114,13 @@ class _CreateScreenState extends State<CreateScreen> {
return 'Utilize valores válidos';
return null;
},
onSaved: (price) {

onSaved: (p) {
ad.price = int.parse(getSanitizedText(p)) / 100;
},
),
HidePhoneWidget(
onSaved: (h){

ad.hidePhone = h;
},
initialValue: false,
),
Expand All @@ -136,6 +139,8 @@ class _CreateScreenState extends State<CreateScreen> {
onPressed: (){
if(_formKey.currentState.validate()){
_formKey.currentState.save();

print(ad);
}
},
),
Expand Down

0 comments on commit a024a5d

Please sign in to comment.