Flutter : 圖片, 動畫, 異步, 手勢檢測, 主題及文字的處理

Image Widget

    1. Image Widget簡介
    • 屏幕快照 2019-06-13 下午2.52.33.png
    1. 支持的圖片格式
    • 屏幕快照 2019-06-13 下午2.53.15.png
    1. 如何加載網絡圖片
    • 屏幕快照 2019-06-13 下午2.54.36.png
    1. 如何加載靜態圖片, 以及處理不同分辨率的圖片
    • 聲明圖片路徑
    • 使用AssetImage / Image.asset訪問圖圖片
    1. 如何加載本地圖片
    • 加載完整路徑的本地圖片
    • 加載相對路徑的本地圖片
    1. 如何設置placeholder

    為了設置Placeholder我們需要借助FadeInImage, 它能夠從內存, 本地資源中加載placeholder

    • 從內存中加載placeholder
    • 從本地資源中加載placeholder
    1. 如何配置圖片緩存
    • 屏幕快照 2019-06-13 下午3.25.32.png
    1. 如何加載Icon
    • Icon的使用
    • 具體代碼
    • 自定義的Icon

Flutter : 動畫

    1. 在Flutter中有哪些動畫?
    • 屏幕快照 2019-06-19 上午10.11.07.png
    1. 如何使用動畫庫中的基礎類給widget添加動畫?
    • 屏幕快照 2019-06-19 上午10.12.16.png
    • Animation
    • CurvedAnimation
    • AnimationController
    • AnimationController注意事項
    • Tween
    • Tween.animate
    1. 為widget添加動畫
    • 代碼示例
    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter/widgets.dart';
    
    class AnimateDemoPage extends StatefulWidget {
      AnimateDemoPage({Key key}) : super(key: key);
    
      _AnimateDemoPageState createState() => _AnimateDemoPageState();
    }
    
    class _AnimateDemoPageState extends State<AnimateDemoPage>
        with SingleTickerProviderStateMixin {
      Animation<double> animation;
      AnimationController controller;
      AnimationStatus animationState;
      double animationValue;
      @override
      void initState() {
        super.initState();
        controller =
            AnimationController(duration: const Duration(seconds: 2), vsync: this);
        animation = Tween<double>(begin: 0, end: 300).animate(controller)
          ..addListener(() {
            setState(() {
              animationValue = animation.value;
            });
          })
          ..addStatusListener((AnimationStatus status) {
            setState(() {
              animationState = status;
            });
          });
      }
      
      @override
      void dispose() {
        // TODO: implement dispose
        controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Container(
          margin: EdgeInsets.only(top: 100),
          child: Column(
            children: <Widget>[
              GestureDetector(
                onTap: (){
                  controller.reset();
                  controller.forward();
                },
                child: Text('Start', textDirection: TextDirection.ltr,),
              ),
              Text('State: ' + animationState.toString(), textDirection: TextDirection.ltr,),
              Text('Value: ' + animationValue.toString(), textDirection: TextDirection.ltr,),
              Container(
                height: animation.value,
                width: animation.value,
                color: Colors.red,
                child: Icon(Icons.fullscreen, color: Colors.blue,),
              )
            ],
          ),
        );
      }
    }
    
    1. 如何為動畫提供監聽器
    • 屏幕快照 2019-06-19 上午10.31.14.png
    1. 用AnimatedWidget與AnimatedBuilder簡化和重構我們對動畫的使用
    • 什么是AnimatedWidget?
    • 代碼示例
    class AnimatedLogo extends AnimatedWidget  {
      const AnimatedLogo({Key key, Animation<double> animation}) : super(key: key, listenable: animation);
    
      @override
      Widget build(BuildContext context) {
        final Animation<double> animation = listenable;
        return Center(
          child: Container(
            margin: new EdgeInsets.symmetric(vertical: 10.0),
            height: animation.value,
            width: animation.value,
            child:  new Text('測試'),
          ),
        );
      }
    }
    
    class LogoApp extends StatefulWidget  {
      LogoApp({Key key}) : super(key: key);
    
      _LogoAppState createState() => _LogoAppState();
    }
    
    class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin {
      Animation<double> animation;
      AnimationController controller;
    
      AnimationStatus animationState;
      double animationValue;
      @override
      void initState() {
        super.initState();
        controller =
            new AnimationController(duration: const Duration(seconds: 2), vsync: this);
        animation = Tween<double>(begin: 0, end: 300).animate(controller)
          controller.forward();
      }
      
      @override
      void dispose() {
        // TODO: implement dispose
        controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return AnimatedLogo(animation: animation,);
      }
    }
    
    1. AnimatedBuilder
    • AnimatedBuilder概述
    • AnimatedBuilder樹狀圖
    • 代碼示例
    class LogoApp extends StatefulWidget  {
      LogoApp({Key key}) : super(key: key);
    
      _LogoAppState createState() => _LogoAppState();
    }
    
    class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin {
      Animation<double> animation;
      AnimationController controller;
    
      AnimationStatus animationState;
      double animationValue;
      @override
      void initState() {
        super.initState();
        controller =
            new AnimationController(duration: const Duration(seconds: 2), vsync: this);
        animation = Tween<double>(begin: 0, end: 300).animate(controller);
        controller.forward();
      }
      
      @override
      void dispose() {
        // TODO: implement dispose
        controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return 
        GrowTransition(
          childWidget: LogoWidget(),
          animation: animation,
        );
        // return AnimatedLogo(animation: animation,);
      }
    }
    
    class LogoWidget extends StatelessWidget {
      const LogoWidget({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Container(
          margin: EdgeInsets.symmetric(vertical: 10),
          child: Text('LogoWidget'),
        );
      }
    }
    
    
    class GrowTransition extends StatelessWidget {
      const GrowTransition({this.animation, this.childWidget});
    
      final Widget childWidget;
      final Animation<double> animation;
      @override
      Widget build(BuildContext context) {
        return Center(
          child: AnimatedBuilder(
            animation: animation,
            builder: (context, child) => Container(
              height: animation.value,
              width: animation.value,
              child: child,
            ),
            child: childWidget,
          ),
        );
      }
    }
    
    1. Hero動畫
    • Hero動畫概述
    • 代碼示例
    import 'package:flutter/material.dart';
    
    class HeroAnimation extends StatelessWidget {
      const HeroAnimation({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        double timeDilation = 10.0;
        return Scaffold(
          appBar: AppBar(
            title: Text('Basic Hero Animation'),
          ),
          body: Center(
            child: PhotoHero(
              photo: '',
              width: 300,
              ontap: () {
                Navigator.of(context)
                    .push(MaterialPageRoute<void>(builder: (BuildContext context) {
                  return Scaffold(
                    appBar: AppBar(
                      title: Text('Flippers Page'),
                    ),
                    body: Container(
                      color: Colors.lightBlueAccent,
                      padding: EdgeInsets.all(15.0),
                      alignment: Alignment.topLeft,
                      child: PhotoHero(
                          photo: '',
                          width: 300,
                          ontap: () {
                            Navigator.of(context).pop();
                          }),
                    ),
                  );
                }));
              },
            ),
          ),
        );
      }
    }
    
    class PhotoHero extends StatelessWidget {
      final VoidCallback ontap;
      final double width;
      final String photo;
      const PhotoHero({Key key, this.photo, this.width, this.ontap})
          : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return SizedBox(
          width: width,
          child: Hero(
            tag: photo, // 關聯兩個動畫的標識
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                onTap: ontap,
                child: Image.network(photo, fit: BoxFit.contain),
              ),
            ),
          ),
        );
      }
    }
    
    

Flutter的異步代碼

    1. 如何編寫異步的代碼?
    • async/await & Isolate
    • async/await的使用
    1. 如何把工作放到后臺線程執行?
    • async/await關鍵字
    • Isolate的使用方法
    • Isolate代碼示例
    • Isolate代碼示例
    1. 如何進行網絡請求
    • http網絡請求使用
    1. 如何為長時間運行的任務添加一個進度指示器?
    • ProgressIndicator的使用
    • 代碼示例 - 1
    • 代碼示例 - 2

手勢檢測 / 觸摸事件處理

    1. 如何給Flutter的widget添加一個點擊事件的監聽?
    • 第一種方法
    • 第二種方法
    1. 如何處理widget上的其他手勢?
    • 屏幕快照 2019-06-25 上午10.50.36.png

主題和文字處理

    1. 如何在Text widget上設置自定義字體?
    • 添加字體
    • 使用字體
    1. 如何在Text上定義樣式?
    • Text的屬性
    1. 如何給App設置主題?
    • 主題概述
    • 代碼示例

Flutter調試技巧

    1. 調試技巧概述:
    • Flutter調試技巧
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,428評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,024評論 3 413
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,285評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,548評論 1 307
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,328評論 6 404
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,878評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 42,971評論 3 439
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,098評論 0 286
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,616評論 1 331
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,554評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,725評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,243評論 5 355
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 43,971評論 3 345
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,361評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,613評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,339評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,695評論 2 370

推薦閱讀更多精彩內容