How to create a form Widget with validators in 3 simple steps I. C8 Global key in a Stateful Widget II. Add Validator to TextFormField Widget III. With Form Key, see Current State and Invoke the validate method Step I: C8 Global key in a Stateful Widget class MyCustomFormState extends State<MyCustomForm> { final _formKey = GlobalKey<FormState>(); @override Widget build(BuildContext context) { return Form( key: _formKey, child: HomePage());}} Step II: Add Validator to TextFormField Widget TextFormField( validator: (form_value) { if (form_value.isEmpty) { return 'Please enter some text'} return null; },); Step III: With Form Key, see Current State and Invoke the validate method RaisedButton( onPressed: () { if (_formKey.currentState.validate()) { Scaffold...
Fat Arrow: "=>" is "{}" Dynamic Vs Object : Semantic Difference for accepting any type, difference is Hashcode is property on Object and Dynamic is when system cannot properly express any type that dev want to use. Print to console with "print()" Quick Guide to Darts Constructor: Used to create object new keyword is optional in Dart2 Declaring Constructor by creating function with same name as class/ syntactic constructor class Point { num x , y ; Point ( num x , num y ) { // There's a better way to do this, stay tuned. this . x = x ; this . y = y ; } } class Point { num x , y ; Point ( this. x , this. y ); } Named Constructor , class name with additional identifier Gives extra clarity when implement multiple constructor within a class Constructor are not inherited, subclass do not inherit superclass's named constructor class Point { num x , y ; Point ( this ....
When importing projects, "Dart SDK is not configured" error code may arise. It can be resolving by linking to bin/cache/dart-sdk in Flutter folder. It usually happens with projects that were created in other machines. To fix this on Android Studio 3.1.3: File-> Settings (ctrl+alt+s) Languages and Frameworks -> Dart Check "Enable Dart support for the project..." In "Dart SDK path" click in "..." and navigate to flutter SDK directory. Under that directory you'll find "bin/cache/dart-sdk" . This is the dart sdk path you should use. Click "Apply" Close the project and open it again (sometimes you need this step, sometimes doesn't) Tip 1: Having problem with fetching a package? Come across this error code: "A dependency may only have one source. sdk: flutter" This may be due to an a n indentation align with sdk (example below). dependencies : flutter : sdk : flutt...
Comments
Post a Comment