flutter-圖片組件(Image)的使用


文檔:https://book.flutterchina.club/chapter5/container.html

加入圖片的幾種方式

  • Image.asset:加載資源圖片,就是加載項目資源目錄中的圖片,加入圖片后會增大打包的包體體積,用的是相對路徑。
  • Image.network:網絡資源圖片,意思就是你需要加入一段http://xxxx.xxx的這樣的網絡路徑地址。
  • Image.file:加載本地圖片,就是加載本地文件中的圖片,這個是一個絕對路徑,跟包體無關。
  • Image.memory: 加載Uint8List資源圖片
//必須有封號  material就是個UI 
import 'package:flutter/material.dart';
//這是個主函數入口
void main()=>runApp(MyApp());
// 也可以這么寫
// void main(){
//   runApp(MyApp())
// }

// 聲明MyApp類
class MyApp extends StatelessWidget{
  // 重寫build
  @override
  Widget build(BuildContext context){
    //返回一個Material風格的App
    return MaterialApp(
      title:'Welcome to Flutteraa',
      home: Scaffold(
        // 在主題的中間區域,添加一個文本  Center:屏幕的中間
        body: Center(
          // child:Container(
          //   child:new Image.network(
          //     'https://avatars2.githubusercontent.com/u/20411648?s=460&v=4',
          //     // scale:1.0,
          //     width: 100.0,
          //     height: 100.0,
          //   ),
          //   width:300.0,
          //   height:300.0,
          //   color: Colors.lightBlue,
          // ),
          child: Container(
            child: Image(
              image: AssetImage("images/2222.png"),
              //縮放模式
              fit: BoxFit.scaleDown,
              color: Colors.greenAccent,
              //背景色 
              colorBlendMode: BlendMode.darken,
              //重復
              repeat: ImageRepeat.repeat,
            ),
            width: 400.0,
            height: 500.0,
            color: Colors.lightBlue,
          ),
        ),
      ),
    );
  }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM