Flutter Cheat Sheet



  1. Flutter Widgets Cheat Sheet Pdf
  2. Flutter Layout Cheat Sheet
  3. Flutter Layout Builder
  4. Flutter Cheat Sheet Medium

Row widget in Flutter uses to display the multiple child widgets in horizontally. Row widget accepts an array of child and you can add any no of widgets.

But when using a row widget there are some tips you need to remember

  1. Row widget is not a scrollable widget
  2. Row widget cannot have a more widget than it can show in the available room and it consider as an error.

The row adjusts its size based on the child content. Therefore you can control the height of the row by controlling the height of the child widgets.

If you want to add space between child widget inside a row there are multiples ways to do that.

  1. Flutter Cheats contains lots of offline ready cheat sheets and tutorials about Flutter and Dart to help you bring your coding skill to the next level and code with more confidence. Flutter and dart knowledge at your fingertips. With lots of tips and code examples.
  2. In this cheat sheet, you will get to learn about some of the best features of codemagic.yaml, as well as get yourself familiarized with it. Mac Pro Business CI/CD How Mac Pro machines are saving you 50% of your mobile app build time.
  3. Julien Loauge makes a wrap-up of the Flutter Container and it's different parameters. Flutter — Container Cheat Sheet.

Do you need simple layout samples for Flutter? I present you my set of Flutter layout code snippets. I will keep it short, sweet and simple with loads of visual examples. Still, it is work in.

You Can simply add a SizedBox to add space between widgets.

Adding Spacer widget between the two widgets will also make a space between those widgets. It will take all the available space and align other widgets to the left corner and right corner

There is no direct property to set the background colour to Row widget. But you can wrap row inside a Container and add a background colour to the container

Row normally takes available space and we can control that by wrapping inside a Container or SizedBox widget. You can wrap the Row inside the Container and add width to the container. Then the Row will take the same width as a Container

Flutter Widgets Cheat Sheet Pdf

If you added a widget which can’t fit into the current frame, it will show an error with the yellow strip by saying overflow. This happens because the row widget is not scrollable.

There are mainly two solutions for that.

  1. If you need to show all items in a horizontal row you must use ListView instead of Row
  2. If you want to move an item to next row you can use Wrap widget instead of row widget

How to use mainAxisAlignment to align children inside a row

The main axis of the Row widget is x-axis( horizontal way). There are multiple ways to align in the main axis.

Align all children to close to the start of the main Axis. This start position identify based on the text direction. If you set textDirection to TextDirection.rtl it will consider start position as right instead of left.

Align all children to end of the main axis. End position identifies base on textDirection.

Place space evenly between the children and also half of the space before and after the first and the last child

Place space evenly between the children as well as space before and after the first and last child

What is Cross Axis of Row widget and How to align in Cross Axis

In the Row widget vertical direction consider as the cross axis. There are multiple properties available to align in Cross Axis.

Sheet

This will place the children with their start edge align with the start of the cross axis. verticalDirection property can use to specify the direction whether from down to top or top to down

This will place the children to the end of the cross axis.

This will place the children to align their center to the middle of cross axis

Place children alone cross axis to match baseline. When you use baseline you has to set textBaseline property also.

I hope you get a better idea about row widget and how to use each property. If you have any question please comment down below

Have you ever wanted to generate a PDF file in flutter? Well, this post is for you. Here, we are going to create a PDF file with content and table in our flutter application. Its pretty easy but first we begin by adding the required dependencies. Open pubspec.yaml and add the following packages.

After adding the packages, we are now going to create a function to populate our table data.

We will then display our data on a table before exporting to pdf

So far when we run our code we will get the following

Now, to export the above data into a PDF file we are going to create a function generatePDF and add all the widgets we need to create our pdf file. This function will be in a separate file called CreatePDF.

Using the pdf package we create a pdf document as follows.

We then add a pages to our document

MultiPage takes multiple parameters which include pageTheme,pageFormat,header, footer and body which in this post is what we are interested in. In our case we will have the following on the page.

You can define your page format within the pageTheme or using the pageFormat parameter. We will display our data within the body of the document which will also include a custom non repeating header and a table.

Create a function named pdfHeader() of Widget typeas follows

Flutter Layout Cheat Sheet

To create the table we use Table.fromTextArray(...) to define the table properties and data.

So far we have created our PDF document and what is left is to save the file. Using path_provider you can define where you want to save the file in local storage in a folder of your choice.

The above code snippets may be confusing but let me make them simpler by providing the complete code in CreatePDF file.

Flutter Layout Builder

Back to the main widget, on the actions menu add the click listener to the FlatButton and then call the generatePDF function.

The _generatePDFData() function generates a multidimensional array of String type as shown below

Flutter Cheat Sheet Medium

Run your code, then click the action menu to create your PDF file. If your file is exported successfully you will get a success message in a Toast.

Viola!





Comments are closed.