Skip to content

Instantly share code, notes, and snippets.

@SoEasy
Created January 20, 2021 13:57
Show Gist options
  • Save SoEasy/9de8d82d54cbcc0734e39f98620d4e1f to your computer and use it in GitHub Desktop.
Save SoEasy/9de8d82d54cbcc0734e39f98620d4e1f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: TextExample(),
);
}
}
class FormData {
final String name;
final double lat;
FormData({ this.name, this.lat });
FormData updateName(String newName) {
return FormData(
name: newName,
lat: lat
);
}
FormData updateLat(double newLat) {
return FormData(
name: name,
lat: newLat
);
}
}
class TextExample extends StatefulWidget {
@override
_TextExampleState createState() => _TextExampleState();
}
class _TextExampleState extends State<TextExample> {
FormData formData = FormData(
name: ''
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sandbox'),
),
body: Column(
children: [
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) {
print('validate name $value');
return null;
},
onChanged: (String value) {
formData = formData.updateName(value);
},
),
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) {
print('validate lat $value');
return null;
},
onChanged: (String value) {
// formData = formData.updateLat(double.parse(value));
},
),
],
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment