Flutter Getting Started Notes 1

Know what Flutter is

Flutter is Google's mobile UI framework, which can quickly build high-quality native user interfaces on iOS and Android. Flutter can work with existing code. Around the world, Flutter is being used by more and more developers and organizations, and Flutter is completely free and open source.

Learn a framework, as usual , look at the document: Flutter Chinese website / Flutter English official website

Flutter ecology

Flutter development environment to build windows version

It is impossible to pretend that you don’t know how to surf the Internet! !

  1. Install the Java environment: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ;
  2. I downloaded Java 8 here:
  3. After the installation is complete, right-click "My Computer", click "Properties", and select "Advanced System Settings";
  4. Select the "Advanced" tab and click "Environmental Variables";
  5. Set 2 attributes in "System Variables", JAVA_HOME, CLASSPATH (the case does not matter), click "New";

Note: If you use JDK version 1.5 or higher, you can compile and run Java programs normally without setting the CLASSPATH environment variable.
Here is the quote
Insert picture description here

  1. Create a new "PATH" variable name in "User Variables", the variable value is: %JAVA_HOME%\bin; (It is the bin directory of jdk, remember that there is a ";" after it)

Here is the quote

  1. After the above three steps are done, click the "Environment Variables" and "OK" after using the shortcut "Ctrl + R" pull "cmd" followed by the command line input java -version, , javaifjavac the following message appears on the configuration was successful, and if that does not work , You can only repeat the above operations and reconfigure again:

Here is the quote
Insert picture description here
Insert picture description here

  1. The shortcut key win + R opens the cmd command line, enter java, if the following figure shows, the installation is successful:
    Insert picture description here
  2. Download and install FlutterSDK: https://flutter.io/sdk-archive/#windows
    Insert picture description here
  3. After downloading, unzip the compressed package, find the file as shown below, double-click to open it: Insert picture description here
    you will get the following interface:
    Insert picture description here
    input flutter -h:
    Insert picture description here

In this step, a VPN may not work well sometimes. At this time, you can consider using a domestic mirror:
Steps:

  1. Computer->Properties->Advanced System Settings->Environment Variables, add the following two under User Variables:
    ① PUB_HOSTED_URL: https://pub.flutter-io.cn
    ② FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io. cn
  2. Restart the computer;
  3. Clear flutter SDK -> bin directory -> cache;
  4. win + R enter cmd to open the command line and enter again flutter -h;
  5. If the fourth step does not work, enter cmd in win + R to open the command line, enter flutter doctor, it is said that it will automatically upgrade (not tried
  1. Configuration path:
    Insert picture description here
    Create a new path, copy the path of the bin folder in the flutter folder, and finally win + R to open the cmd command line and enter it flutter -h. If it is consistent with the previous display, the configuration is successful;
    Insert picture description here
  2. win + R to open the cmd command line input flutter doctorconfiguration, diagnostics environment better, and usually ×do not work properly:
    Insert picture description here
  3. Download and install Android Studio ;

For specific steps, please refer to the rookie tutorial ;

  1. Install the flutter plug-in on Android Studio:
    Insert picture description here
    Insert picture description here
    restart after installation, you will find an extra line (as shown below):
    Insert picture description here

  2. At this time, then win + R cmd to open the command line, type flutter doctor:
    Insert picture description here
    a visual cue that we certificate is not installed, and gave us the command line to install the certificate, we follow the input flutter doctor --android-licensescan be:
    Insert picture description here
    When you install it will ask you many questions, all ythat will be enough ;

  3. Enter again at this time flutter doctor, and you will find the last exclamation point: the
    Insert picture description here
    reason is that the virtual machine has not been installed;

  4. In the next step, we first build a flutter project:
    Insert picture description here
    then I am stuck directly, and I don’t know why, so I decided to win + R to open the cmd command line, enter flutter create 项目名:
    Insert picture description here
    then enter Android Studio to open the project manually:
    Insert picture description here
    and then this step is too Slow, let me add two proxy URLs to my user variables:
    Insert picture description here
    Insert picture description here

  • FLUTTER_STORAGE_BASE_URLhttps://storage.flutter-io.cn
  • PUB_HOSTED_URL: https://pub.flutter-io.cn
    Then I felt that the speed was not good, and I went online for another wave of science, and it was finally possible!
  1. The next step is to install the AVD virtual machine: Insert picture description here
    Insert picture description here
    Insert picture description here
    Click on the latest version to download: After the
    Insert picture description here
    download is complete, click Run: When
    Insert picture description here
    the virtual machine is turned on for the first time, it may pop up:
    Insert picture description here
    Solution: Often an error is reported because the SDK is not selected.
    Click [File]-[Project Structure]-[Project SDK], and fill in the SDK path correctly.
    Insert picture description here
    After opening the virtual machine, type flutter doctor in the terminal:
    Insert picture description here
    you will find that all the tick boxes are marked!

  2. After opening the virtual machine, click Debug:
    Insert picture description here
    Then I failed : I
    Insert picture description here
    checked it seems to be because the gradle version is too low, I will try to update it:
    Insert picture description here
    Then after a whole wave, it probably means that the minimum supported version must be at least gradle 6.5, and then I ran up and down again:
    Insert picture description here
    I looked at the gradle official website and found that the version was 6.7.1, which was high and stable, and that was it. After a download, I found the gradle folder in the computer. The path is probably: C:\Users\86135.gradle\wrapper\dists, everyone is similar, you can refer to
    Insert picture description here
    there are probably so many versions, but the previous ones are automatically downloaded before, I have not manually installed them, each There is a fixed garbled directory under the version of the gradle file directory:
    Insert picture description here
    the source code of this garbled extraction is below:
    Insert picture description here
    you can modify the version you want to install to get it:

package com.java.test1;

import java.math.BigInteger;
import java.security.MessageDigest;

public class Test1 {
    
    

	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		System.out.println(getHash("https://services.gradle.org/distributions/gradle-6.7.1-all.zip"));
//		System.out.println(getHash("https://services.gradle.org/distributions/gradle-3.2-all.zip"));
	}
	
	private static String getHash(String string) {
    
     
		try {
    
     
			MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 
			byte[] bytes = string.getBytes(); 
			messageDigest.update(bytes); 
			return new BigInteger(1, messageDigest.digest()).toString(36); 
		} catch (Exception e) {
    
     
			throw new RuntimeException("Could not hash input string.", e); 
			} 
		}
}

Then change this again:
Insert picture description here
this time I click Debug and it won't work, but it will be fine after restarting!
Insert picture description here

Write Flutter code under VSCode

First, open our VSCode, download Flutter and Dart plug-ins;

Then, we create a file named EmulatorRun.bat on the desktop, right-click to edit, find the path of emulator.exe in our computer and the name of the virtual machine, and set the delay and speed:
Insert picture description here
After filling in Ctrl + S to save, after closing, Right-click to run as an administrator, and you can run the virtual machine directly:
Insert picture description here
Next, keep the virtual machine turned on, we go back to VSCode, Ctrl + Shift + ~open the terminal, and enter flutter run:
Insert picture description here
there is a more convenient way to open the virtual machine:
Insert picture description here
as shown in the figure Show, click [No Device] in the lower right corner of VSCode, select or create a new virtual machine:
Insert picture description here

The first Hello World program

Delete all the codes in the main.dart file, and we rewrite it ourselves:

//引入UI库,material-ui官网:https://material-ui.com/zh/
import 'package:flutter/material.dart'; //dart与js不同,dart是一定要加末尾的分号的

void main() {
    
    
  runApp(MyApp());
}
/*
同样的意思,使用箭头函数的写法:
void main() => runApp(MyApp());
*/

class MyApp extends StatelessWidget {
    
    
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    
    
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

Then enter flutter runrun in the terminal :
Insert picture description here
you can see that the run is successful, we should pay attention to the shortcut keys in the red box;

Flutter update

Flutter over the future as the updated version, you can enter directly in the terminal flutter upgradeupdate can;
but after a general update is complete, simply run flutter runis not being given the run, so the first flutter clean, another flutter run;

Flutter project file structure

Insert picture description here

How to archive image resources and handle different resolutions?

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

How to archive strings resources and handle different languages?

Insert picture description here
Insert picture description here
Insert picture description here

How to add the dependencies required by the Flutter project?

Insert picture description here
Insert picture description here
See the Pub official website for details ;

Who is the View in Flutter?

Insert picture description here
Insert picture description here

How to update Widgets?

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

How to add or remove components in the layout?

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

How to animate Widget?

Insert picture description here
Insert picture description here
Insert picture description here
???

How to draw (Canvas draw/paint)?

Insert picture description here
Insert picture description here
Insert picture description here

Draw circles and squares

Insert picture description here
Insert picture description here
Insert picture description here

How to build custom Widgets?

Insert picture description here
Insert picture description here

How to set the transparency of Widget?

Insert picture description here

Guess you like

Origin blog.csdn.net/Jessieeeeeee/article/details/110949068