This folder allows you to quickly find what you need to learn about Flutter!!
π create a Flutter project π
Here we create the Flutter project using the Android Studio installed Flutter plugin
Android Studio main screen -> Create Flutter Project
Note: π the four functions in the screenshot above
Flutter Application
: Create aFlutter
Application engineeringFlutter plugin
: This is for givingAndroid
εiOS
Use when providing plug-in applications (exposed excuses)Flutter Package
: Create aThe Dart components
Release topub
To provide easy development of some third party librariesFlutter Module
: Generally used for mixed development, embedded intoAndroid
εiOS
Work in progress!
Once created, we can run Flutter for the first time to feel the Flutter classic default page
π the declaration of Flutter is π
Imperative programming
: Tell the “machine” how to do things so that whatever you want it to do will happen.Declarative programming
: Tell the machine what you want and let the machine figure out how to do it.
Maybe you can’t figure out what imperative programming is and what declarative programming is by using a view UI as π°, okay
First let’s look at a representative of imperative programming: object-c
UIView *view = [[UIView alloc] init];
view.frame = self.view.bounds;
view.backgroundColor = [UIColor orangeColor];
Copy the code
We tell the machine: The layout of the view is self.view. The background color of the bounds view is orangeColor and if you need to change the view, you usually need to use the selector findViewById or something like that to get the instance view and ownership of the ViewB, And call the associated modified method (and implicitly invalidate it).
view.backgroundColor = [UIColor blueColor];
Copy the code
Since the actual source of the UI may have a longer lifetime than the instance View itself, you may also need to copy this configuration in the view constructor
In the declarative style, the view configuration (such as the Widget of the Flutter) is immutable; it is simply a lightweight “blueprint”. To change the UI, the widget triggers a rebuild on itself (the most common method in Flutter is to call setState() on the StatefulWidgets component) and constructs a new widget subtree.
// Declarative style
return ViewB(
color: red,
child: ViewC(...),
)
Copy the code
It is clear that the two modes focus on completely different points! If there is not quite understand, might as well see twice will have a feeling!!
π Preliminary experience of Flutter Project π
With some understanding of the declarative syntax above, let’s start playing around with the code. First of all, you may understand the code, but only at a cursory level. Now let’s learn, bit by bit! First kill the entire program some code, leave π
Let’s start writing a simple code
πβ Experience the Flutter text component π
#import
import 'package:flutter/material.dart';
// The main function the program runs (entry 0)
void main() {
UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate Class]));
// Because the world of Flutter is full of parts
// Here we simply use Center to write a text
runApp(Center(
child: Text(
'Study harmoniously without being impatient'./ / text
textDirection: TextDirection.ltr, // Alignment
style: TextStyle(
fontSize: 40.0.// Font size
color: Colors.red, // Red font
fontWeight: FontWeight.w400, // The size of the font)))); }Copy the code
Doesn’t it feel refreshing that the code of Flutter itself is relatively easy? After all, don’t you find that the syntax structure of Flutter tends to be larger and more unified?
πβ‘ Experience the Flutter navigation bar π
class KCBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold( / / nav
appBar: AppBar( / / the navigation bar
title: Text('KCFlutterBar',style: TextStyle(color: Colors.white),), ), body: KCWidget(), floatingActionButton: FloatingActionButton(), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling, ), theme: ThemeData( primaryColor: Colors.orange ), ); }}Copy the code
Let’s have a look at the effect of the display, or relatively OK!
You’re smart enough to know that as you write, the code is still a little bit awkward. Here I recommend you a few shortcut keys, convenient for you to quickly beautiful programming
Command + o
: Global searchcommand + option + l
: Formatting codecommand + l
: Comment codecommand + -
: Collapses and expands codecommand + [
: code returncommand + ]
: Code forwardcmd + C / cmd + delete
: delete rowsctr + alt + I
: Auto indent alignmentopt + sft + up/down
: Moves the code up and downctrl + tab
: Switch filesshift + command + enter
: automatically add semicolon at the end of line, if automatically add “(){}”cmd + N
: Quickly generate getters/setters, constructors, toString() methods, etccmd + J
: Quickly generate template code blocks, such as if,while,returnopt + cmd + T
Surround with…… Surround with…… Catch,while, etcopt + ctr + o
: Deletes unused import filesoption + enter
: Automatically imports the packages usedstless
: Create a newStatelessWidget
stful
: Create a newStatefulWidget
πβ’ The flutter listView page is π
class KCListView extends StatelessWidget {
Widget _itemForRow(BuildContext context, int index) {
return Container(
color: Colors.white,
margin: EdgeInsets.fromLTRB(10.10.10.10),
child: Column(
children: <Widget>[
Image.network(carDatas[index].imageUrl),
SizedBox(height: 10),
Text(
carDatas[index].name,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w800,
fontStyle: FontStyle.values[1]),
),
SizedBox(height: 10),,),); }@override
Widget build(BuildContext context) {
returnListView.builder( itemBuilder: _itemForRow, itemCount: carDatas.length, ); }}Copy the code
Load the list structure using the navigation style to load the data. If you follow along, you can easily feel the power of declarative syntax. It’s easy to write an application if you know how to write it with a previous understanding of UI layout (β οΈ flexible box layout, Flex β οΈ)
If you also tap into the code, you can go to github: Flutter column code, where the whole column code is kept up to date. If you like, please like π
π 4. Conclusion π
This article about the initial experience of Flutter may be because you are just a little Flutter white feeling is not strong, but it doesn’t matter how much you tap on Flutter, the more you really tap on this thing, the more you will feel, the better to tap muscle memory! The simplicity of the Flutter code is strong. You’ll grow to love tapping the Flutter code!
Come on! Let’s tap Flutter together: Github: Flutter column code
We will dive into Flutter details at the beginning of our next article! Don’t get lost
Dry goods address: like can be a key three