Flutter Dev Portfolio – part 3 (Header Body)

Developer Portfolio Header Section

In the header_view.dart, under headerView, let’s extract the content. So the text, images, logo, etc.
All of that content is the Expanded child of the Row. let’s click on ‘Column’ of the Expanded child and Extract Widget

Then you’ll see that it has been extracted as the HeaderBody, and we instantiate it where our old code was. Notice that the logo is outside of our HeaderBody.

Now let’s put it inside our HeaderMobileView.

Now run the app, make it into mobile size and we see our header’s contents. Notice that our FlutterLogo is NOT shown because we did not include it in our HeaderBody.

We need to add some padding, logo and what not. So we need to wrap our HeaderBody inside of a column. That way, we can add padding, put a logos, and what not as children.

The code should look like this:

And now we see the logo in mobile view.

Now let’s add some padding.

Adding Auto Size Text

ref – https://pub.dev/packages/auto_size_text/install

Let’s add auto size text wdiget to our pubspec.yaml file. It is a Flutter widget that automatically resizes text to fit perfectly within its bounds. So say we specify that we want want our sentence to fit in two lines. Normally, when we start typing out the sentence, if it doesn’t fit, it’ll appear on line 2, then line 3. But with auto size text, the font size of the text will decrease so that it fits within two lines. And if we keep typing, and the widget sees that the text will start to overflow to line 3, it’ll decrease the font size some more so that our sentence will only fit in those two lines.

Installing auto size text

Flutter will then install it.

Once installed, let’s change Text to AutoSizeText like so:

isMobile property

In HeaderBody, add property isMobile by cmd + dot.

Then let’s specify that whenever we’re on mobile, we give it a smaller font or size.

In HeaderView, find the HeaderBody and pass in isMobile boolean from size object.

In HeaderMobileView, since its a mobile view, let’s always give it a true value for HeaderBody