The welcome screen, the login screen and the registration screen all have the same style of button. The code for this button should ideally be in a separate class in its own file.
-
Locate the
Padding
widget that contains theMaterialButton
in the welcome_screen.dart. Make a note of the colours of the buttons. You'll need these colours later. -
Extract the entire
Padding
widget into a separate StatelessWidget calledRoundedButton
. -
Add three properties to the
RoundedButton
: aColor
variable, aString
variable for button title, and aFunction
variable for the button'sonPressed
callback. Modify theRoundedButton
's constructor so that these properties are assigned a value when aRoundedButton
is created. -
Modify the code in the
RoundedButton
to replace the hard-coded title, colour, and onPressed callback to use the three properties you created above. -
Create a new directory under
lib
calledcomponents
. Insidecomponents
create a new file calledrounded_button.dart
. -
Add the code for the
RoundedButton
class to the new file. -
Refactor the code in the welcome_screen.dart, the login_screen.dart, and the registration_screen.dart to use the
RoundedButton
. Hint: Leave the code inside the callback for the button'sonPressed
on the login and registration screen blank (for now).
The TextField
for entering the email (and password) is heavily styled by the decoration
property. Let's extract the code for the InputDecoration
and add it to the constants.dart
file instead. There the decoration can sit alongside its friends which will also further simplify our registration_screen.dart
and login_screen.dart
.
-
In the
constants.dart
create a newconst
calledkTextFieldDecoration
. Set this constant equal to theInputDecoration
used to style the email and password fields. -
Make use of the
kTextFieldDecoration
on theregistration_screen.dart
andlogin_screen.dart
.
Hint: Vary the hintText
using .copyWith()
.