flutter reading this, APP is not a dream, free to blow your friends back

First, look at our demo today we build out of Sha Yangzi

In this article we talk about stuff there

a. layout structure

b. navBar

c. Use the list of components and tabbar

d. http request JSON data, and to render list

Communication between e. Components

f. route (routing parameters)

Ado, directly open dry

First, a flutter of powerful features is its cool domineering UI library, the official portal: Material-UI library

http://www.material-ui.com/#/

Here everyone can choose their favorite of the UI components.

navBar

First to do this demo, we want to split what structure

  1. There must be a bottom navigation bar

  2. We were bottom of the navigation bar to the corresponding interface (hypothesis 3)

ok, let's establish that these dart file named, respectively, the first interface, a second interface, the third interface

Next, we give every child a tab interface, adding a simple code structure, such an effect is rendered

Which scaffold is a scaffold, it can be understood as a html, appBar is above the titlebar, body would not have said it

With these three interfaces, we can return to main.dart in to add a bottom navigation, and associate them all!

First, we want to introduce these three tab interface to our parent component is in main.dart like this

Introducing components

Then, we have to transform our main the following widget, like this

Which is TabController tabbar controller,

Then we initState () initialization time, pay attention to the length property that is expressed several tab, the rest do not have control, when walking the process it.

Then is the home of the Scaffold to join in a bottomNavigationBar, this is what we understand about a look, the bottom navigation bar

Then a new child TabBar inside out, tabs TabBar property of which contains a Tab widget array, each Tab is below the corresponding icon and copy, controller is the controller, you should have a good understanding of it.

body: is a TabBarView widget, and attributes which are TabBar widget corresponds to the.

Also remember to join SingleTickerProviderStateMixin, remember good, do not get to the bottom.

Then flutter run run, to achieve a simple bottom of the navigation.

Note: There is no use appBar property, because the definition of the tab subassembly, added here will generate the two appbar.

Now we'll add a list component sub-assemblies

We will focus on firstPage in it.

We list is defined as a puppet component, then we put him into the components inside, and the effect of the following codes:

main.dart

components/list.dart

Layout layout

Here we will talk about the layout.

First put the official portal: flutter layout widget

2 can be roughly divided into two categories:

  1. Single-child layout widgets; parent widget can only contain a single child widget

There are: Contrainer, Padding, Center etc.

  1. Multi-child layout widgets; parent in the widget comprises a plurality of sub-stages can widget

There are: Row, Column and so on

An official instance, we can show a very good understanding of more complex layout

layout examples

To put it plainly, layout is the way layers of building blocks, and H5 essentially the same, layer by layer entered, write, multi-child layout widget support flex default layout, you can mainAxisAlignment (spindle attributes) and crossAxisAlignment ( vertical axis attribute) to flex layout.

mainAxisAlignment: MainAxisAlignment.spaceBetween

crossAxisAlignment: CrossAxisAlignment.center。

So far, we get a list, then we will request via http interface will bind JSON data returned to our list up.

http request

dart offers io library

dart: I

Type conversion library

dart:convert

http get requests

Note: Because with the new version, in which the code has the following changes:

UTF8.decoder => utf8.decoder

json.decode => jsonDecode

We define a getData () method, followed with a async, is to solve the asynchronous, of course, is back to await, we should know everything.

Anyway, that is a very standard http request, in response.statusCode == HttpStatus.OK when (or == 200), you get the data we want, then JSON.decode it, then setState method, give us the widget defined parameter assignment, then you can use. FIG next, out of the red circle is to be used. I define this parameter as data.

Data Binding

In this way, JSON data on the success of rendering.

Rendering data

A list of items certainly can click to see him go into the details page, so then we have to achieve this small function.

routing

Here it is to use the routing function.

Official examples are as follows: Official Navigation + routing links

Examples of official Router

In our app, the wording is almost the same, but we need to first define our router address in our main.dart

main.dart set route

In this way, we can in the other interface, through the path "/ detail", the route to this interface.

However normal application, we will take some more or less routing parameters, such that the interface to the next, the parameters may be utilized to implement some logic or requests, etc., here we look at how parameters are passed route:

Route passing parameters

Left is the list interface, the right is the detail interface, do:

  1. ListTile added to the list in onTap event, and then define a _onTap function, which accepts a String parameter to id,

  2. In a push navigator pageRouteBuilder, we directly written out Detail class returns, to bring the parameter ID. (Of course, we advance in this screen, the Detail of import in, otherwise return a hanging ah ..). Behind the transition is over-animation (now do not bother, anyway, this code is official).

  3. In Detail.dart sure to define the parameters you need to pass the name of, or on the gg. Finally, they can do whatever they want, ha ha.

Here, click on each corresponding list item will jump to the corresponding detail screen, and the list of items in the id attribute, pass together in the past, and displayed by the top left back button, you can return to the list page, as shown below:

Routing parameter passing

Communication Components

In vue, react variety of popular era, we thought that component-based, flutter can not be lost. Next we come to realize that what communication between components. That we are in the <notification> This tab is achieved in a simple component of communication. Directly on the code:

Organize communications

Left parent component:

  1. We are here to do an input box, and then define a parameter: active

  2. Monitor changes in input value by changing the input of onChanged event, and assigned to the active component Input

The right subcomponents:

  1. Values ​​following code received over the transmission of the active

Input({Key key, this.active})

: super(key: key);

  1. Change in the value displayed in active

Communication Components

This realizes a simple communication parent element of the subassembly.

Related

Next: flutter basis - component communication (father and son, brother)

Epilogue

Here Benpian ended, with more of these technical points, enough to complete our line and a simple but complete app out of it, we have the opportunity to try on their own, every minute line and a app.

The article is written too hastily, but also pure new sprouting, so if there is no logic to rationalize the things wrong, we would like a direct message spray!

Author: partial Luo

Links: https://www.jianshu.com/p/bb69f81f6236

Source: Jane books

Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source. First, look at our demo today we build out of Sha Yangzi

In this article we talk about stuff there

a. layout structure

b. navBar

c. Use the list of components and tabbar

d. http request JSON data, and to render list

Communication between e. Components

f. route (routing parameters)

Ado, directly open dry

First, a flutter of powerful features is its cool domineering UI library, the official portal: Material-UI library

http://www.material-ui.com/#/

Here everyone can choose their favorite of the UI components.

navBar

First to do this demo, we want to split what structure

  1. There must be a bottom navigation bar

  2. We were bottom of the navigation bar to the corresponding interface (hypothesis 3)

ok, let's establish that these dart file named, respectively, the first interface, a second interface, the third interface

Next, we give every child a tab interface, adding a simple code structure, such an effect is rendered

Which scaffold is a scaffold, it can be understood as a html, appBar is above the titlebar, body would not have said it

With these three interfaces, we can return to main.dart in to add a bottom navigation, and associate them all!

First, we want to introduce these three tab interface to our parent component is in main.dart like this

Introducing components

Then, we have to transform our main the following widget, like this

Which is TabController tabbar controller,

Then we initState () initialization time, pay attention to the length property that is expressed several tab, the rest do not have control, when walking the process it.

Then is the home of the Scaffold to join in a bottomNavigationBar, this is what we understand about a look, the bottom navigation bar

Then a new child TabBar inside out, tabs TabBar property of which contains a Tab widget array, each Tab is below the corresponding icon and copy, controller is the controller, you should have a good understanding of it.

body: is a TabBarView widget, and attributes which are TabBar widget corresponds to the.

Also remember to join SingleTickerProviderStateMixin, remember good, do not get to the bottom.

Then flutter run run, to achieve a simple bottom of the navigation.

Note: There is no use appBar property, because the definition of the tab subassembly, added here will generate the two appbar.

Now we'll add a list component sub-assemblies

We will focus on firstPage in it.

We list is defined as a puppet component, then we put him into the components inside, and the effect of the following codes:

main.dart

components/list.dart

Layout layout

Here we will talk about the layout.

First put the official portal: flutter layout widget

2 can be roughly divided into two categories:

  1. Single-child layout widgets; parent widget can only contain a single child widget

There are: Contrainer, Padding, Center etc.

  1. Multi-child layout widgets; parent in the widget comprises a plurality of sub-stages can widget

There are: Row, Column and so on

An official instance, we can show a very good understanding of more complex layout

layout examples

To put it plainly, layout is the way layers of building blocks, and H5 essentially the same, layer by layer entered, write, multi-child layout widget support flex default layout, you can mainAxisAlignment (spindle attributes) and crossAxisAlignment ( vertical axis attribute) to flex layout.

mainAxisAlignment: MainAxisAlignment.spaceBetween

crossAxisAlignment: CrossAxisAlignment.center。

So far, we get a list, then we will request via http interface will bind JSON data returned to our list up.

http request

dart offers io library

dart: I

Type conversion library

dart:convert

http get requests

Note: Because with the new version, in which the code has the following changes:

UTF8.decoder => utf8.decoder

json.decode => jsonDecode

We define a getData () method, followed with a async, is to solve the asynchronous, of course, is back to await, we should know everything.

Anyway, that is a very standard http request, in response.statusCode == HttpStatus.OK when (or == 200), you get the data we want, then JSON.decode it, then setState method, give us the widget defined parameter assignment, then you can use. FIG next, out of the red circle is to be used. I define this parameter as data.

Data Binding

In this way, JSON data on the success of rendering.

Rendering data

A list of items certainly can click to see him go into the details page, so then we have to achieve this small function.

routing

Here it is to use the routing function.

Official examples are as follows: Official Navigation + routing links

Examples of official Router

In our app, the wording is almost the same, but we need to first define our router address in our main.dart

main.dart set route

In this way, we can in the other interface, through the path "/ detail", the route to this interface.

However normal application, we will take some more or less routing parameters, such that the interface to the next, the parameters may be utilized to implement some logic or requests, etc., here we look at how parameters are passed route:

Route passing parameters

Left is the list interface, the right is the detail interface, do:

  1. ListTile added to the list in onTap event, and then define a _onTap function, which accepts a String parameter to id,

  2. In a push navigator pageRouteBuilder, we directly written out Detail class returns, to bring the parameter ID. (Of course, we advance in this screen, the Detail of import in, otherwise return a hanging ah ..). Behind the transition is over-animation (now do not bother, anyway, this code is official).

  3. In Detail.dart sure to define the parameters you need to pass the name of, or on the gg. Finally, they can do whatever they want, ha ha.

Here, click on each corresponding list item will jump to the corresponding detail screen, and the list of items in the id attribute, pass together in the past, and displayed by the top left back button, you can return to the list page, as shown below:

Routing parameter passing

Communication Components

In vue, react variety of popular era, we thought that component-based, flutter can not be lost. Next we come to realize that what communication between components. That we are in the <notification> This tab is achieved in a simple component of communication. Directly on the code:

Organize communications

Left parent component:

  1. We are here to do an input box, and then define a parameter: active

  2. Monitor changes in input value by changing the input of onChanged event, and assigned to the active component Input

The right subcomponents:

  1. Values ​​following code received over the transmission of the active

Input({Key key, this.active})

: super(key: key);

  1. Change in the value displayed in active

Communication Components

This realizes a simple communication parent element of the subassembly.

Related

Next: flutter basis - component communication (father and son, brother)

Epilogue

Here Benpian ended, with more of these technical points, enough to complete our line and a simple but complete app out of it, we have the opportunity to try on their own, every minute line and a app.

The article is written too hastily, but also pure new sprouting, so if there is no logic to rationalize the things wrong, we would like a direct message spray!

The above information may need to add QQ group: 668 041 364

Guess you like

Origin blog.51cto.com/14233733/2413687