We will be talking about how to reuse widgets and create custom reusable AppBars in this article.
It’s so easy in flutter. Composing widgets and making it a more powerful and reusable one is so much easy in flutter.
Let’s say I want some TextFormField in my application and I want it to be of similar look and feel. So there is a tendency of writing methods like this below. Assume that you have a Utils class where we add all the utility methods…
import 'package:flutter/material.dart';
class Utils {
//
static getTF(TextEditingController controller) {
return TextFormField(
controller: controller,
);
}
}
and now to add in the UI….
body: Container(
child: Column(
children: [
Utils.getTF(_emailController),
...
Well, this definitely works…, but do you see that it doesn’t look like a widget. This is one of the common mistakes that beginners do…
You can customize this function by sending more parameters and thereby customizing the ‘TextFormField’ widget…still this is the wrong way.
Flutter is more powerful to easily handle this…
Let’s see the proper way to do this…
#flutter #mobile