Flutter——Widget系列5、资源assets、pubs

2019-08-27  本文已影响0人  阿敏其人

pubspec.yaml 文件

项目的静态资源,需要配置到根目录下的pubspec.yaml文件。

image.png

以静态图片为例子:

image.png image.png
  assets:
    - images/lake.jpg
    - images/pic1.jpg
    - images/pic2.jpg
    - images/pic3.jpg
    - images/pic4.jpg

那么,使用一下吧。


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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
//    final wordPair = new WordPair.random();

    return MaterialApp(
      title: 'Flutter 测试标题',
//      home: new RandomWords(),
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text("app title"),
        ),
        body: new Center(
          child: new Image.asset('images/lake.jpg'),
        ),
      ),

      theme: new ThemeData(
        primaryColor: Colors.red,
      ),

    );
  }
}
image.png

说的是图片,如果是视频,建立video之类文件夹就可以。照猫画虎。

使用播放器,可以看看官方教程
https://flutter-io.cn/docs/cookbook/plugins/play-video.html


上一篇 下一篇

猜你喜欢

热点阅读