当前位置:网站首页>Flutter common development problems
Flutter common development problems
2022-06-24 05:11:00 【nuts】
“ This paper mainly introduces Flutter Common development problems ”
Flutter Using a completely new approach , You can use widgets Instead of Views .Android Medium View It is mainly an element of the layout , But in Flutter in ,Widget Almost everything . Everything from buttons to layout structures are widgets . The advantage here is that it can Customization . Imagine Android One of the buttons in . It has attributes such as text , Allows you to add text to the button . however Flutter The button in does not take the title as a string , It's another widget . It means ** You can have text inside the button 、 Images 、 Icons and almost anything you can imagine ,** Without breaking the layout restrictions . This also makes it very easy for you to make custom widgets , And in the Android It is quite difficult to make custom views in .
Isn't it easier to drag and drop than to make a layout in your code ?
in some ways , Such is the case . however Flutter Many people in the community prefer the code approach , But that doesn't mean you can't drag . If you absolutely love dragging , that Flutter Studio It is a great resource I recommend , It can help you generate layouts by dragging and dropping . This is a tool that impresses me , I really want to see how it develops .
link :https : //flutterstudio.app
Flutter Whether it works like a browser ?/ It is based on WebView What's the difference between our applications ?
Simply answer this question : You are WebView Code written by a running application must go through multiple layers before it can be finally executed . essentially ,Flutter Compile to native ARM Code to execute on both platforms , So that stride across .“ blend ” The application is slow 、 slow , And it looks different from the platform they run on .Flutter Applications run much faster than their hybrid applications . Besides , Using plug-ins to access native components and sensors is more important than using a that cannot take full advantage of its platform WebView More easily .
Why? Flutter There are Android and iOS Folder ?
Flutter The project mainly includes 3 A folder :lib、android and ios.'lib' Responsible for handling your Dart file .Android and iOS Folders exist to actually build applications on their respective platforms , And run on it Dart file . They also help you add permissions and platform - specific functionality to your projects . When you run Flutter Project time , It will be built according to the running simulator or device , Use the folder to Gradle or XCode structure . In short , These folders are the entire application , They are Flutter The running of the code lays the foundation .
Why my Flutter So big ?
If you have run Flutter Applications , You will know it fast . Extremely fast . How it does it ? When building an application , It doesn't just use specific resources , It is Virtually all resources . Why does this help ? Because if I change an icon from one to another , You do not have to completely rebuild the application . This is it. Flutter debugging The reason for building so large . When creating a release , Only the required resources will be obtained , And get the size we're more used to .Flutter Applications will still be better than Android The application is larger , But it's quite small , and Flutter The team has been looking for ways to reduce the size of the application .
If I'm new to programming , I want to start with the development of mobile terminals , It should be from Flutter Do you want to start ?
There are more two-part answers .
- Flutter Perfect for writing code , And the code on the same page is better than Android or iOS There are far fewer applications . So for most applications , I don't think there will be a big problem .
- One thing you need to remember is Flutter It also depends on Android and iOS project , At a minimum, you need to be familiar with the project structure . If you want to write any native code , You definitely need experience on either or both platforms .
My personal opinion is to study for oneortwo months first Android/iOS, And then from Flutter Start .
What is? package And plug-ins ?
package Allow you to Add new widgets or features Import your application .package There is a small difference between and plug-ins . The package is usually purely for Dart New components or code written , The plug-in can use native code to provide more functions on the device side . Usually in DartPub On , Both packages and plug-ins are called packages , The difference is only explicitly mentioned when creating a new package .
What is? pubspec.yaml file , What does it do ?
Pubspec.yaml Allows you to define the packages that your application depends on , Declare your assets , Such as images 、 Audio 、 Video etc. . It also allows you to set constraints for your application . about Android For developers , This is roughly similar to build.gradle file , But the difference between the two is also obvious .
Why the first Flutter Application building takes so long ?
First build Flutter Application time , Will build specific On The equipment APK or IPA file . therefore , Use Gradle and XCode Building files takes time . The next time you restart or hot load the application ,Flutter Basically patch changes on top of existing applications , So as to provide extremely fast refresh .
Be careful : Changes made by hot reload or restart are not saved In the device APK or IPA In file . To ensure that your app makes all changes on the device , Consider stopping and running the app again .
state What does that mean? ? What is? setState()?
** Simply speaking ,“ state ” Is a collection of widget variable values .** Anything that can be changed , Such as counter counting 、 Text etc. , Can be State Part of . Imagine a counter application , The main dynamic is counter counting . When the count changes , The screen needs to be refreshed to display the new value .setState() It is essentially a way to tell an application to refresh and rebuild the screen with new values .
What are stateful and stateless widgets ?
TL;DR: The widgets that allow you to refresh the screen are stateful widgets . Stateless widgets are stateless .
In more detail , A dynamic widget whose content can be changed should be a stateful widget . Stateless widgets can only change content when changing parameters , So it needs to be done above the location point in the widget hierarchy . A screen or widget that contains static content should be a stateless widget , But change the content , There needs to be a state .
How do you deal with Flutter Indentation and structure in code ?
Android Studio Provides tools to simplify Flutter The structure of the code . The two main points are :
- Alt + Enter/ Command + Enter: This makes it easy to wrap and delete widgets and swap widgets in complex hierarchies . In order to use it , Simply point the cursor at the widget declaration and press the key to provide some options . It sometimes feels like a godsend .
- DartFMT:dartfmt Format your code to keep the hierarchy and indentation clean . After you accidentally move a few parentheses , It will make your code more beautiful .
Why do we pass functions to widgets ?
We pass a function to a widget , In essence, it means ,“ Call this function when something happens ”. The function is Dart The first type of object in , It can be passed as an argument to other functions . Use Android (<Java 8) There are too many boilerplate codes for simple callbacks .
Java Callback :
button.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
// Do something here
}
}
);( Be careful , This is just the code to set up the listener . Defining a button requires a separate XML Code .)
Dart equivalent:
FlatButton(
onPressed: () {
// Do something here
}
)(Dart Both declaration and callback settings .)
It becomes clearer and more organized , And help us avoid unnecessary complications
边栏推荐
- Tencent cloud installs Kedao cloud - build an exclusive private cloud disk
- Functional advantages of industrial wireless router
- Here's all you want to know about takin data (1) startup command
- Bi-sql and & or & in
- How RedHat 8 checks whether the port is connected
- PHP sizeof() function
- What is the new generation cloud computing architecture cipu of Alibaba cloud?
- Some excellent plug-ins on Amway vscode
- The principle of defer keyword in go
- System design: index
猜你喜欢

Training methods after the reform of children's programming course

Leetcode (question 2) - adding two numbers

014_ TimePicker time selector

CTF learning notes 18:iwesec file upload vulnerability-03-content-type filtering bypass

少儿编程课程改革后的培养方式

What are the disadvantages of the free IP address replacement tool?

011_ Cascader cascade selector

Analysis on the subjective enthusiasm of post-90s makers' Education

Popularization of children's programming education in specific scenarios

Leetcode (question 1) - sum of two numbers
随机推荐
PHP sizeof() function
[Yunyue plan] Tencent's cloud industry opening is based on the digital marketing of games such as king / eating chicken / fighting landlords and private domain marketing
Tencent cloud installs Kedao cloud - build an exclusive private cloud disk
Develop a customized music player from scratch, and your girlfriend will have it?
[leetcode daily question] push domino
The principle of defer keyword in go
Many regulations come into effect today! The main responsibility of network security will be further implemented
How does a R & d make a small demand bigger and bigger step by step
Bi-sql and & or & in
Is there a free ECS? What should I pay attention to when I rent a server
Powerbi - for you who are learning
Webmeng: create a website you are proud of
Pgbouncer lightweight PG connection pool management tool
PTA 1041 seat number (15 points)
Spirit breath development log (15)
CTF learning notes 18:iwesec file upload vulnerability-03-content-type filtering bypass
2021-08-27: the normal odometer will display natural numbers in turn to indicate mileage, Kyrgyzstan
PTA 1066 image filtering (15 points)
What is the difference between a traditional data center and a cloud computing data center?
Use of golang testing framework test