主頁 > 移動端開發 > Flutter學習筆記

Flutter學習筆記

2021-02-22 10:24:46 移動端開發

1、flutter的開始

1、認識檔案夾

在這里插入圖片描述

檔案夾名稱作用
androidandroid平臺相關代碼
iosios平臺相關代碼
libflutter相關代碼,主要撰寫的代碼放入該檔案夾
test用于存放測驗代碼
pubspec.yaml組態檔,專案相關資訊,一般存放第三方庫的依賴

2、入口檔案/入口方法

入口檔案:flutter專案的lib目錄里面都有一個main.dart這個檔案就是flutter的入口檔案

入口方法:main.dart檔案中的

void main() {
  runApp(MyApp());
}
//也可也簡寫一下
void main()=>runApp(MyApp());

其中main方法是dart的入口方法,runApp方法是flutter的入口方法,MyApp是自定義的一個組件,

2、flutter基本

從最根本的開始哦,

1、Helloworld

import 'package:flutter/material.dart';

void main() {
  runApp( Center(
    child: Text(
      'CDX',
      textDirection: TextDirection.ltr,
    )
  ));
}

實作效果:

在這里插入圖片描述

2、自定義組件

在flutter中自定義組件其實就是一個類,這個類需要繼承StatelessWidget/StatefulWidget,

StatelessWidget:是無狀態組件,狀態不可變的widget,

StatefulWidget:是有狀態組件,持有的狀態可能在widget生命周期改變,

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Text(
      'CDX111',
      textDirection: TextDirection.ltr,
      style: TextStyle(
        fontSize: 40.0,
        color: Colors.yellow,
      ),
    ));
  }
}

實作效果:

在這里插入圖片描述

3、組件:MaterialApp/Scaffold

1、MaterialApp組件是一個方便的Widget,它封裝了應用程式實作Material Design所需要的一些Widget,一般作為頂層widget使用,

2、Scaffold組件是Material Design布局結構的基本實作,此類提供了用于顯示drawer、snackbar和底部sheet的API,

代碼塊:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: HomeContent(),
      ),
    );
  }
}
class HomeContent extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Text(
      'CDX111',
      textDirection: TextDirection.ltr,
      style: TextStyle(
        fontSize: 40.0,
        color: Colors.yellow,
      ),
    ));
  } 
}

完整代碼:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: HomeContent(),
      ),
    );
  }
}

class HomeContent extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Text(
      'CDX111',
      textDirection: TextDirection.ltr,
      style: TextStyle(
        fontSize: 40.0,
        color: Colors.yellow,
      ),
    ));
  } 
}

實作效果:

在這里插入圖片描述

4、組件:Container/Text 詳解

1、Container組件

該組件可以被用來看作是我們之前的一個div,其實他就是一個物件,我們來看一下他的建構式吧,

在這里插入圖片描述

Container組件屬性描述

屬性名型別說明
keyKeyContainer 一識別符號,用于查找更新
alignmentAlignmentGeometry控制child 的對齊方式,如果Container或者 Container 父節點尺寸大于child 的尺寸,這個屬性設定會起作用,有很多種對齊方式
paddingEdgelnsetsGeometryDecoration內部的空白區域,如果有child的話,child 位于padding 內部
colorColor用來設定 Contain 背景色,如果foregroundDecoration設定的話,可能會遮蓋color效果
decorationDecoration繪制在child后面的裝飾,設定了 Decoration 話,就不能設定color 屬性,否則會報錯,此時應該在 Decoration中進行顏色的設定
foregroundDecorationDecoration繪制在child前面的裝飾
widthdoubleContainer的寬度,設定為double.infinity可以強制在寬度上撐滿,不設定,則根據child和父節點兩者一起布局
heightdoubleContainer的高度,設定為double.infinity可以強制在高度上撐滿
constraintsBoxConstraints添加到child上額外的約束條件
marginEdgelnsetsGeometry圍繞在Decoration和child之外的空白區域,不屬于內容區域
transformMatrix4設定Container的變換矩陣,型別為Matrix4
childWidgetContainer中的內容Widget

2、Text組件

Text組件屬性描述

屬性名型別默認值說明
dataString資料為要顯示的文本
maxLinesint0文本顯示的最大行數
styleTextStylenull文本樣式,可定義文本的字體大小、顏色、粗細等
textAlignTextAlignTextAlign.center文本水平方向對齊方式,取值有center、end、justify、left、right、start、values
textDirectionTextDirectionTextDirection.ltr文本書寫方向,ltr從左到右,rtl從右到左
textScaleFactordouble1.0字體縮放系數
textSpanTextSpannull文本塊

3、示例

//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        child: Text(
          'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
          textAlign: TextAlign.center,
          overflow: TextOverflow.fade,
          style: TextStyle(
              fontSize: 16.0,
              color: Colors.red,
              fontWeight: FontWeight.w700,
              fontStyle: FontStyle.italic,
              decoration: TextDecoration.lineThrough,
              decorationColor: Colors.white,
              decorationStyle: TextDecorationStyle.dashed),
        ),
        height: 300.0,
        width: 300.0,
        decoration: BoxDecoration(
            color: Colors.green,
            border: Border.all(color: Colors.blue, width: 2.0),
            borderRadius: BorderRadius.all(Radius.circular(150))
            ),
            transform: Matrix4.rotationZ(0.3),
      ),
    );
  }
}

效果:

在這里插入圖片描述

5、圖片組件

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在HomeContent中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、介紹

1、new Image:從ImageProvideer 獲取圖片

2、new Image.asset:加載資源圖片

3、new Image.file:加載本地圖片檔案

4、new Image.netWork:加載網路圖片

5、new Image.memory:加載Uint8List資源圖片,

Image組件屬性描述

屬性名型別說明
imageImageProvider抽象類,需要自己實作獲取圖片資料的操作
width/hei ghtdoubleImage顯示區域的寬度和高度設定
fitBoxfit圖片填充模式
colorColor圖片顏色
colorBlendModeBlendMode在對圖片進行手動處理的時候,可能會用到圖片混合如改變圖片的顏色,此屬性可以對顏色進行混合處理,
alignmentAlignment控制圖片的擺放位置
repeatImageRepeat設定圖片重復模式
centerSliceRect當圖片需要被拉伸時使用
matchTextDirectionbooI該屬性與Directionlity配合使用
gaplessPlaybackbool當ImageProvide發生變化后,重新加載圖片的程序中,原圖片的展示是否保留

BoxFit取值描述

取值描述
Boxfit.fill全圖顯示,顯示可能拉伸,充滿
Boxfit.contain全圖顯示,顯示原比例,不需充滿
Boxfit. cover顯示可能拉伸,可能裁剪,充滿
BoxFit.fitWidth顯示可能拉伸,可能裁剪,寬度充滿
BoxFit.fitHeight顯示可能拉伸,可能裁剪,高度充滿
Boxfit.none原始大小
BoxFit.scaleDown效果和BoxFit.contain差不多,但是此屬性不允許顯示超過源圖片大小,即可小不可大

2、遠程圖片示例

mage.network(src)

簡單示例:

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        child: Image.network(
          "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1675144683,641372710&fm=26&gp=0.jpg",
        colorBlendMode: BlendMode.screen,
        fit: BoxFit.cover,),
        width: 300,
        height: 300,
        decoration: BoxDecoration(
          color: Colors.green,
        ),
      ),
    );
  }
}

效果:

在這里插入圖片描述

3、實作圓角以及圓形圖片

1、使用borderRadius和BoxFit.cover實作

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
      width: 300,
      height: 300,
      decoration: BoxDecoration(
        color: Colors.green,
        borderRadius: BorderRadius.circular(150),//*********
        image: DecorationImage(
          image: NetworkImage(      "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1675144683,641372710&fm=26&gp=0.jpg",
          ),
          fit: BoxFit.cover,//************
        ),
      ),
    ));
  }
}

效果:

在這里插入圖片描述

2、使用ClipOval實作

1、首先看clipOval處理的效果

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
          child: ClipOval(
            child: Image.network("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1675144683,641372710&fm=26&gp=0.jpg",),
          ),
    ));
  }
}

效果:

在這里插入圖片描述

2、繼續變圓

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
          child: ClipOval(
            child: Image.network("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1675144683,641372710&fm=26&gp=0.jpg",
            height: 300,
            width: 300,
            fit: BoxFit.cover,),
          ),
    ));
  }
}

效果:

在這里插入圖片描述

2、本地圖片

1、相關檔案夾的創建與組態檔修改

在這里插入圖片描述

2、示例

1、代碼

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Container(
          child: Image.asset("images/1.jpg"),
    ));
  }
}

2、效果

在這里插入圖片描述

6、串列組件

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在HomeContent中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、介紹

串列大致有以下分類

1、水平的串列

2、垂直的串列

3、資料量非常大的串列

4、矩陣式的串列

ListView組件的基本屬性

屬性名型別默認值說明
scrollDirectionAxisAxis.vertical串列的排列方向,Axis.vertical為垂直方法式默認值,Axis.horizontal為水平方法
paddingEdgelnsetsGeometry串列內部的空白區域,如果有child的話,child位于padding內部
reverseboolfalse組件排列反向
childrenList串列元素,注意List元素全部為Widget

2、垂直串列

代碼:

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        ListTile(
          leading: Image.asset("images/1.jpg"),
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
        ),
        ListTile(
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
          trailing: Icon(Icons.search),
        ),
        ListTile(
          leading: Icon(Icons.padding),
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
        ),
        ListTile(
          leading: Icon(Icons.games),
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
        ),
        ListTile(
          leading: Icon(Icons.ac_unit_sharp),
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
        ),
        ListTile(
          leading: Icon(Icons.tab),
          title: Text("xxxxxxxxxxxxxxxxxxxxx"),
          subtitle: Text("ccccccccccccccccccc"),
        ),
      ],
    );
  }
}

效果:

在這里插入圖片描述

3、水平串列

代碼:

class HomeContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 200,
      child:ListView(
      scrollDirection: Axis.horizontal,
      children: <Widget>[
        Container(
          width: 100,
          height: 100,
          color: Colors.green,
        ),
        Container(
          width: 100,
          height: 100,
          color: Colors.blue,
        ),
        Container(
          width: 100,
          height: 100,
          color: Colors.red,
        ),
        Container(
          width: 100,
          height: 100,
          color: Colors.grey,
        ),
        Container(
          width: 100,
          height: 100,
          color: Colors.deepOrange,
        ),
      ],
    )
    );
  }
}

效果:

在這里插入圖片描述

4、動態串列

代碼:

class HomeContent extends StatelessWidget {
  List<Widget> getData() {
    List<Widget> list = new List();
    for (var i = 1; i <= 7; i++) {
      list.add(ListTile(
        title: Text("xxxxxx$i個"),
      ));
    }
    return list;
  }
  @override
  Widget build(BuildContext context) {
    return Container(child: ListView(children: this.getData()));
  }
}

ListView.builder

class HomeContent extends StatelessWidget {
  List list = new List();
  HomeContent() {
    
    for (var i = 1; i <= 7; i++) {
      list.add("xxxxxx$i個");
    }
  }
  @override
  Widget build(BuildContext context) {
    return Container(child: ListView.builder(
      itemCount: this.list.length,
      itemBuilder: (context,index){
        return ListTile(
          title: Text(this.list[index]),
        );
      },
    ));
  }
}

效果:

在這里插入圖片描述

7、GridView組件

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

GridView組件屬性及描述

屬性名型別默認值說明
scrollDirectionAxisAxis.vertical滾動的方向,有垂直和水平兩種,默認為垂直方向
reverseboolfalse默認是從上或者左向下或者向右滾動的,這個屬性控制是否反向,默認值為false,即不反向滾動
controllerScrollController控制child滾動時候的位置
primarybool是否是與父節點的PrimaryScrollcontroller所關聯的主滾動視圖
physicsScrollPhysics滾動的視圖如何回應用戶的輸入
shrinkWrapboolfalse滾動方向的滾動視圖內容是否應該由正在查看的內容所決定
paddingEdgeinsetsGeometry四周的空白區域
gridDelegateSliverGridDelegate控制GridView中子節點布局的delegate
cacheExtentdouble快取區域

1、通過GridView.count實作網格布局

代碼:

class Demo extends StatelessWidget {
  List<Widget> getData() {
    List<Widget> list = new List();
    for (var i = 0; i < 20; i++) {
      list.add(Container(
        alignment: Alignment.center,
        child: Text(
          'xxxxx $i xxxx',
          style: TextStyle(color: Colors.white,fontSize: 20),
        ),
        color: Colors.blue,
      ));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      crossAxisSpacing: 10.0, //水平子Widget之間的距離
      mainAxisSpacing: 10.0, //垂直widget之間距離
      padding: EdgeInsets.all(10),
      crossAxisCount: 3, //控制一行有多少個Widget
      childAspectRatio: 0.7,//寬度和高度的比例
      children: this.getData(),
    );
  }
}

效果:

在這里插入圖片描述

2、通過GridView.builder實作網格布局

代碼:

class Demo extends StatelessWidget {
  Widget getData(context, index) {
    return Container(
      child: Column(
        children: <Widget>[
          Image.asset("images/1.jpg"),
          SizedBox(height: 12),
          Text(
            "xxxxxxxx",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 20),
          )
        ],
      ),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.blue, width: 1),
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      // padding: EdgeInsets.all(10),
      // crossAxisCount: 3, //控制一行有多少個Widget
      // childAspectRatio: 0.7,//寬度和高度的比例
      // children: this.getData(),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisSpacing: 10.0, //水平子Widget之間的距離
        mainAxisSpacing: 10.0, //垂直widget之間距離
        crossAxisCount: 3, //控制一行有多少個Widget
      ),
      itemCount: 10,
      itemBuilder: this.getData,
    );
  }
}

效果:

在這里插入圖片描述

8、頁面布局 Padding/Row/Column/Expanded

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

GridView組件屬性及描述

1、Padding組件

在html中常見的布局標簽都有padding屬性,但是Fliuuter中很多widget是沒有padding屬性的,這時候我們可以用Padding組件處理容器與子元素之間的間距

屬性說明
paddingpadding值,EdgeInsetss設定填充的值
child子組件

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView.count(
      padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
      crossAxisCount: 3, //控制一行有多少個Widget
      childAspectRatio: 1.7,//寬度和高度的比例
      children: <Widget>[
        Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
         Padding(
          padding: EdgeInsets.fromLTRB(10, 10, 0, 0),
          child: Image.asset("images/1.jpg",fit: BoxFit.cover,),
        ),
      ],
    );
  }
}

效果:

在這里插入圖片描述

2、Row水平布局組件

屬性介紹:

屬性說明
mainAxisAlignment主軸的排序方式
crossAxisAlignment次軸的排序方式
children組件子元素

3、Column垂直布局組件

實作一個圖示組件:實作傳入圖示(顏色和大小動態)

代碼:

class IconDemo extends StatelessWidget {
  double size = 32.0;
  Color color = Colors.red;
  IconData icon;
  IconDemo(this.icon, {this.color, this.size});
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100.0,
      width: 100.0,
      color: this.color,
      child: Center(
        child: Icon(
          Icons.home,
          size: 32,
          color: Colors.white,
        ),
      ),
    );
  }
}

通過上述組件測驗Row的排序

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 600.0,
      width: 600.0,
      child:Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      crossAxisAlignment: CrossAxisAlignment.start,
      
      children: <Widget>[
        IconDemo(
          Icons.home,
          color: Colors.green,
        ),
        IconDemo(
          Icons.search,
          color: Colors.red,
        ),
        IconDemo(
          Icons.fit_screen,
          color: Colors.green,
        ),
      ],
    )
    );
  }
}

class IconDemo extends StatelessWidget {
  double size = 32.0;
  Color color = Colors.red;
  IconData icon;
  IconDemo(this.icon, {this.color, this.size});
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100.0,
      width: 100.0,
      color: this.color,
      child: Center(
        child: Icon(
          Icons.home,
          size: 32,
          color: Colors.white,
        ),
      ),
    );
  }
}

效果:

在這里插入圖片描述

4、Expanded組件

Flutter中Expanded組件類似Web中的Flex布局

Expanded可以用在Row和Column布局中

屬性說明
flex元素占整個父Row/Column的比例
child子元素

代碼:(未包含上述IconDemo組件的代碼)

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Expanded(
          flex: 1,
          child: IconDemo(
            Icons.home,
            color: Colors.green,
          ),
        ),
        Expanded(
          flex: 2,
          child: IconDemo(
            Icons.search,
            color: Colors.red,
          ),
        ),
      ],
    );
  }
}

效果:

在這里插入圖片描述

5、相關案例

實作一個類似于下圖的布局

在這里插入圖片描述

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Expanded(
              child: Container(
                height: 200,
                color: Colors.blue,
                child: Text("xxxxxxxxxx"),
              ),
            )
          ],
        ),
        SizedBox(height: 10),
        Row(children: <Widget>[
          Expanded(
              flex: 2,
              child: Container(
                  height: 180,
                  child: Image.asset(
                    "images/1.jpg",
                    fit: BoxFit.cover,
                  ))),
          Expanded(
              flex: 1,
              child: Container(
                  height: 180,
                  child: ListView(children: <Widget>[
                    Container(
                        height: 85,
                        child: Image.asset(
                          "images/1.jpg",
                          fit: BoxFit.cover,
                        )),
                    SizedBox(height: 10),
                    Container(
                        height: 85,
                        child: Image.asset(
                          "images/1.jpg",
                          fit: BoxFit.cover,
                        ))
                  ]))),
        ]),
      ],
    );
  }
}

效果:

在這里插入圖片描述

9、頁面布局 Stack層疊組件/Stack與Aligin/Stack與Positioned

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、Stack組件

屬性說明
alignment配置所有子元素的顯示位置
children子組件

stack效果:有點像元素重疊一樣,下面展示文字和容器效果

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Container(
          height: 400,
          width: 300,
          color: Colors.red,
        ),
        Text("xxxxxxxxxxx")
      ],
    );
  }
}

效果:

在這里插入圖片描述

通過alignment屬性進行位置移動

在這里插入圖片描述

還可以是坐標

alignment: Alignment(0,0),

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      // alignment: Alignment.center,
      // alignment: Alignment(0,0),
      alignment: Alignment.center,
      children: <Widget>[
        Container(
          height: 400,
          width: 300,
          color: Colors.red,
        ),
        Text("xxxxxxxxxxx")
      ],
    );
  }
}

效果:

在這里插入圖片描述

2、align/positiond

上述stack如果里面有兩個文本的話,就會導致兩個文本出現重疊的現象如下:

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      // alignment: Alignment.center,
      // alignment: Alignment(0,0),
      alignment: Alignment.center,
      children: <Widget>[
        Container(
          height: 400,
          width: 300,
          color: Colors.red,
        ),
        Text("xxxxxxxxxxx"),
        Text("ddddddddddd"),
      ],
    );
  }
}

效果:

在這里插入圖片描述

使用align

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        height: 400,
        width: 400,
        color: Colors.blue,
        child: Stack(children: <Widget>[
          Align(
            alignment: Alignment.topLeft,
            child:  Icon(Icons.help, size: 40, color: Colors.white),
          ),
          Align(
            alignment: Alignment.center,
            child: Icon(Icons.search, size: 40, color: Colors.white),
          ),
          Align(
            alignment: Alignment.bottomRight,
            child: Icon(Icons.home_filled, size: 40, color: Colors.white),
          ), 
        ]),
      ),
    );
  }
}

效果:

在這里插入圖片描述

使用positiond
屬性說明
top子元素距離頂部的距離
bottom子元素距離底部的距離
left子元素距離左側的距離
right子元素距離右側的距離
child子組件

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        height: 400,
        width: 400,
        color: Colors.blue,
        child: Stack(children: <Widget>[
          Positioned(
            left: 10,
            child:  Icon(Icons.help, size: 40, color: Colors.white),
          ),
          Positioned(
            bottom: 0,
            child: Icon(Icons.search, size: 40, color: Colors.white),
          ),
          Positioned(
            right: 0,
            child: Icon(Icons.home_filled, size: 40, color: Colors.white),
          ), 
        ]),
      ),
    );
  }
}

效果:

在這里插入圖片描述

10、AspectRatio組件/Card組件

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、AspectRatio

AspectRatio的作用是根據設定調整子元素child的寬高比,

AspectRatio首先會在布局限制條件允許的范圍內盡可能的擴展,widget的寬度是由寬度和比率決定的,類似于BoxFit中的contain,按照固定比率去盡量占滿區域,

如果在滿足所有限制條件過后無法找到一個可行的尺寸,AspectRatio最終將會去優先適應布局限制條件,而忽略所設定的比率

屬性說明
aspectRatio寬高比,最終可能不會根據這個值去布局,具體要看綜合因素,外層是否允許按照這種比例進行布局,這只是一個參考值
child子組件

代碼:(長是高的2倍例子)

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 200,
      child: AspectRatio(
        aspectRatio: 2.0/1.0,//外層的200,會是里面的container長200高100
        child: Container(
          color: Colors.red,
        ),
      ),
    );
  }
}

2、Card

Card是卡片組件塊,內容可以由大多數型別的Widget構成,Card具有圓角和陰影,這讓它看起來有立體感,

屬性說明
margin外邊距
child子組件
ShapeCard的陰影效果,默認的陰影效果為圓角的長方形邊,

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        Card(
          margin:EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                title:Text('chidaoxian'),
                subtitle: Text('前端開發工程師'),
              ),
               ListTile(
                title:Text('電話:12323432141234123'),
               
              ),
               ListTile(
                title:Text('地址:xxxxxx'),
                
              ),
            ],
          ),
        ),
        Card(
          margin:EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              ListTile(
                title:Text('chidaoxian'),
                subtitle: Text('前端開發工程師'),
              ),
               ListTile(
                title:Text('電話:12323432141234123'),
               
              ),
               ListTile(
                title:Text('地址:xxxxxx'),
                
              ),
            ],
          ),
        ),
      ],
    );
  }
}

效果:

在這里插入圖片描述

11、Wrap組件

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、介紹

wrap組件可以實作流布局,單行的Wrap跟Column表現幾乎一致,單列的Wrap則跟Row表現幾乎一致,但Row與Column都是單行單列,Wrap則突破了這個限制,mainAxis上空間不足時,則向crossAxis上去擴展顯示,

屬性說明
direction主軸的方法,默認水平
alignment主軸的對齊方式
spacing主軸方向上的間距
textDirection文本方向
verticalDirection定義了children擺放順序,默認是down,見flex相關屬性介紹
runAlignmentrun的對齊方式,run可以理解為新的行或者列,如果是水平方向布局的話,run可以理解為新的一行
runSpacingrun的間距

2、wrap實體

代碼:

class Demo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing:10,
      // runSpacing:5,
      children: <Widget>[
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
      MyButton('xxx'),
    ]);
  }
}
class MyButton extends StatelessWidget {
  final String text;
  const MyButton(this.text, {Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      child: Text(this.text),
      textColor: Theme.of(context).accentColor,
      onPressed: () {},
    );
  }
}

效果:

在這里插入圖片描述

12、StatefulWidget有狀態組件、頁面上系結資料、改變頁面資料

基礎代碼塊:(本節代碼基礎部分,其余效果展示代碼均在Demo中)

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Demo(),
      ),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

1、介紹

StatefulWidget是有狀態組件,持有的狀態可能在Widget生命周期改變,通俗的講:如果我們想改變頁面中的資料的話這個時候就需要用到StatefulWidget,

2、有狀態組件/資料系結

代碼:

class Demo extends StatefulWidget {
  Demo({Key key}) : super(key: key);

  @override
  _DemoState createState() => _DemoState();
}

class _DemoState extends State<Demo> {
  int countNum = 0;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        SizedBox(height: 20,),
        Chip(label: Text('${this.countNum}')),
        SizedBox(height: 20,),
        RaisedButton(
          child: Text('按鈕'),
          onPressed: (){
            setState(() {
              this.countNum++;
            });
          },
        )
      ],
    );
  }
}

效果:

在這里插入圖片描述

13、ButtonNavigationBar組件

1、介紹

ButtonNavigationBar 是底部導航條,可以讓我們定義底部Tab切換,buttonNavigationBar是Scaffold組件引數,

屬性名型別說明
currentlndexint當前索引,用來切換按鈕控制
fixedColorColor選中按鈕的顏色,如果沒有指定值,則用系統主題色
iconSizedouble按鈕圖示大小
itemsList底部導航調按鈕集,每一項是一個BottomNavigationBarItem,有icon圖示及title文本屬性
onTapValueChanged按下其中某一個按鈕回呼事件,需要根據回傳的索引設定當前索引

2、實體

1、效果:

底部導航切換頁面效果:

在這里插入圖片描述

在這里插入圖片描述

代碼介紹:

在這里插入圖片描述

在這里插入圖片描述

代碼:

1、main.dart的代碼

import 'package:flutter/material.dart';
import 'package:flutter_app01/pages/tabs/Home.dart';
import 'pages/tabs/Tabs.dart';
import 'pages/tabs/ddd.dart';
import 'pages/tabs/Setting.dart';

void main() {
  runApp(MyApp());
}

//自定義組件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Tabs(),
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
    );
  }
}

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int currentIndex = 0;

  List pageList = [
    HomePage(),
    SettingPage(),
    DDDPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: this.pageList[this.currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: this.currentIndex,
          onTap: (int index) {
            setState(() {
              this.currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '首頁',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.my_library_books),
              label: '我的',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.settings_applications),
              label: '設定',
            ),
          ],
        ),
      ),
    );
  }
}

2、Tabs.dart的代碼

import 'package:flutter/material.dart';

class Tabs extends StatefulWidget {
  Tabs({Key key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text('flutter cdx'),
        ),
        body: Text('xxx'),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: this.currentIndex,
          onTap: (int index) {
            setState(() {
              this.currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '首頁',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.my_library_books),
              label: '我的',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.settings_applications),
              label: '設定',
            ),
          ],
        ),
      ),
    );
  }
}

3、Home.dart的代碼(Home.dart/Setting.dart代碼類似)

import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Text('HomePage'),
    );
  }
}

14、Flutter中的基本路由

flutter中的路由通俗的講就是頁面跳轉,在flutter中通過Navigator組件管理路由導航,并提供了管理堆疊的方法,如:Navigator.push 和Navigator.pop

flutter中給我們提供了兩種配置路由跳轉的方式:1、基本路由 2、命名路由

1、簡單路由跳轉

在這里插入圖片描述

代碼:

import 'package:flutter/material.dart';
import '../Search.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        RaisedButton(
          child: Text('跳轉搜索頁面'),
          onPressed: (){
            Navigator.of(context).push(
             MaterialPageRoute(
               builder: (context)=> SearchPage()
             )
            );
          },
        ),
      ],
    );
  }
}

2、跳轉傳值

在這里插入圖片描述

代碼:

import 'package:flutter/material.dart';

class SearchPage extends StatefulWidget {
  SearchPage({Key key}) : super(key: key);

  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  String title ;
  _SearchPageState({this.title = 'cdx'});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("${this.title}頁面"),
      ),
      body: Text("內容區域"),
    );
  }
}


3、回傳

在這里插入圖片描述

代碼:

import 'package:flutter/material.dart';

class SearchPage extends StatefulWidget {
  SearchPage({Key key}) : super(key: key);

  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  String title ;
  _SearchPageState({this.title = 'cdx'});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Text('回傳'),
        onPressed: (){
          Navigator.of(context).pop();
        },
      ),
      appBar: AppBar(
        title: Text("${this.title}頁面"),
      ),
      body: Text("內容區域"),
    );
  }
}

效果:

在這里插入圖片描述

15、Flutter命名路由

1、不攜帶引數

main.dart檔案配置:**

在這里插入圖片描述

路由跳轉方式:

在這里插入圖片描述

2、攜帶引數

Routes.dart檔案

import 'package:flutter/material.dart';
import 'package:flutter_app01/pages/tabs/Tabs.dart';
import 'package:flutter_app01/pages/tabs/ddd.dart';
import 'package:flutter_app01/pages/tabs/Setting.dart';
import 'package:flutter_app01/pages/Search.dart';
import 'package:flutter_app01/pages/tabs/Home.dart';

final routes = {
  '/': (context, {arguments}) => Tabs(),
  '/home': (context, {arguments}) => HomePage(),
  '/ddd': (context, {arguments}) => DDDPage(),
  '/setting': (context, {arguments}) => SettingPage(),
  '/search': (context, {arguments}) => SearchPage(arguments: arguments),
};

//主要方法
var onGenerateRoute = (RouteSettings settings) {
  final String name = settings.name;
  final Function pageContentBuilder = routes[name];
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route =   MaterialPageRoute(builder: (context) =>  pageContentBuilder(context, argumens: settings.arguments));
      return route;
    } else {
      final Route route =  MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};

main.dart檔案

import 'package:flutter/material.dart';
import 'package:flutter_app01/routes/Routes.dart';

void main() {
  runApp(MyApp());
}

//自定義組件
class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.green,
      ),
      // home: Tabs(),
      initialRoute: '/', //初始化的時候加載的路由
      onGenerateRoute: onGenerateRoute,

    );
  }
}

16、路由替換/回傳根路由

1、替換路由

就是替換當前的頁面,

在這里插入圖片描述

2、回傳跟路由

在這里插入圖片描述

待入的組件表格屬性介紹

Form組件

屬性名型別說明
keyKey組件在整個Widget樹中的key值
autovalidatebool是否自動提交表單
childWidget組件child只能有一個子組件
onChangedVoidCallback當FormFiled值改變時的回呼函式

TextFromField組件

屬性名型別說明
autovalidatebool自動驗證值
initialValueT表單欄位初始值
onSavedFormFieldSetter當Form表單呼叫保存方法Save時回呼函式
validatorFormFieldValidatorForm表單驗證器

Material Design風格組件

組件名稱中文名稱簡單說明
AppBar應用按鈕組件應用的工具按鈕
AlertDialog對話框組件有操作按鈕的對話框
BottomNavigationBar底部導航條組件底部導航條,可以很容易地在tap之間切換和瀏覽頂級視圖
Card卡片組件帶有邊框陰影的卡片組件
Drawer抽屜組件Drawer抽屜組件可以實作類似抽屜拉開關閉的效果
FloatingActionButton浮動按鈕組件應用的主要功能操作按鈕
FlatButton扁平按鈕組件扁平化風格的按鈕
MaterialAppMaterial應用組件Material App代表使用紙墨設計風格的應用
PopupMenuButton彈出選單組件彈出選單按鈕
Scaffold腳手架組件實作了基本的Material Design 布局
SnackBar輕量提示組件一個輕量級訊息提示組件,在螢屏的底部顯示
SimpleDialog簡單對話框組件簡單對話框組件,只起提示作用,沒有互動
TabBar水平選項卡及視圖組件一個顯示水平選項卡的Material Design組件
TextField文本框組件可接受應用輸入文本的組件

MaterialApp

屬性名型別說明
titleString應用程式的標題,該標題出現在如下位置:Android:任務管理器的程式快照之上 IOS:程式切換管理器
themeThemeData定義應用所使用的主題顏色,可以指定一個主題中每個控制元件的顏色
colorColor應用的主要顏色值,即 primary color
homeWidget這個是一個Widget物件,用來定義當前應用打開時,所顯示的界面
routesMap<String,WidgetBuider>定義應用中頁面跳轉規則
initialRouteString初始化路由
onGenerateRouteRouteFactory路由回呼函式,當通過Navigator.of(context).pushNamed跳轉路由時,在routes查找不到時,會呼叫該方法
onLocaleChanged當系統修改語言的時候,會觸發這個回呼
navigatorObserversList導航觀察器
debugShowMaterialGridbool是否顯示紙墨設計基礎布局網格,用來除錯UI的工具
showPerformanceOverlaybool顯示性能標簽

Scaffold

屬性名型別說明
appBarAppBar顯示在界面頂部的一個AppBar
bodyWidget當前界面所顯示的主要內容
floatingActionButtonWidget在Material Design中定義的一個功能按鈕
persistentFooterButtonsList在固定在下方顯示的按鈕
drawerWidget側邊欄組件
bottomNavigationBarWidget顯示在底部的導航欄按鈕欄
backgroundColorColor背景顏色
resizeToAvoidBottomPaddingbool控制界面內容body是否重新布局來避免底部被覆寫,比如當鍵盤顯示時,重新布局避免被鍵盤蓋住內容,默認值為true

AppBar及SliverAppBar組件

屬性名型別默認值
leadingWidgetnull
titleWidgetnull
actionsListnull
bottomPreferredSize Widgetnull
elevationdouble4
flexibleSpaceWidgetnull
backgroundColorColorThemeData.primaryColor
brightnessBrightnessThemeData.primaryColorBrightness
iconThemeIconThemeDataThemeData.primaryIconTheme
textThemeTextThemeThemeData.primaryTextTheme
centerTitlebooltrue

介紹:

屬性名說明
leading在標題前面顯示的一個組件,在首頁通常顯示應用的logo;在其他界面通常顯示
titleToolbar中主要內容,通常顯示為當前界面的標題文字
actions一個Widget串列,代表Toolbar中所顯示的選單,對于通常的選單,通常使用IconButton來表示,對于不太常用的選單通常使用PopupMenuButton來顯示為三點,點擊后彈出二級選單
bottom通常是TabBar,用來在Toolbar標題下面顯示一個Tab導航欄
elevation紙墨設計中組件的z坐標順序,對于可滾動的SliverAppBar,當SliverAppBar和內容同級的時候,該值為0,當內容咕噥的那個SliverAppBar變為ToolBar的時候,修改elevation
flexibleSpace一個顯示在AppBar下方的組件,高度和AppBar高度一樣,可以實作一些特殊的效果,該屬性通常在SliverAppBar中使用
backgroundColor背景色
brightnessAppBar的亮度,有白色和黑色兩種主題
iconThemeAppBar上圖示的顏色、透明度和尺寸資訊,默認值為ThemeData. primaryIcon Theme
textThemeAppBar上的文字樣式
centerTitle標題是否居中顯示,默認值根據不同的作業系統,顯示方式不一樣

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/262069.html

標籤:其他

上一篇:Mac m1恢復出廠設定

下一篇:[NOIP1998 提高組] 拼數

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more