Also it's a good way to make your own Method or widget.(So you can reuse code later)
Example:
//your generator method or you can make your own widget class if you want that.
Widget _entryField(String title, {bool isPassword = false}) {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
SizedBox(
height: 10,
),
TextField(
obscureText: isPassword,
decoration: InputDecoration(
//labelText: title , // you can change this with the top text like you want
hintText: "Please enter your $title" ,
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true))
],
),
);
}
==============
# **Edit:** #
As mentioned by @Evin1_ below.
After reading this article [Splitting widgets to methods is a performance antipattern/Iiro Krankka][1]
I found it's better to use *StatelessWidget* to split your code and functions only for doing Operations.
**the reason:**
This way, you won’t be rebuilding your static widget trees multiple times for nothing but wasted CPU cycles.
If you really prefer building your widget trees with methods, you might want to take a look at a package called functional_widget by [Remi Rousselet][2].
**Also** others comments for more information about this topic here [ difference between functions and classes to create reusable widgets][3]
[1]:
[To see links please register here]
[2]:
[To see links please register here]
[3]:
[To see links please register here]