How to load images with image.file

后端 未结 11 2132
星月不相逢
星月不相逢 2021-01-01 10:41

I can\'t seem to simply load an image from the hard drive to the screen. Image.network seems straightforward. But I can\'t figure out how to use Image or Image.file. Imag

11条回答
  •  长发绾君心
    2021-01-01 11:09

    Here is another example which uses a jpg as a background image. It also applies opacity to the image.

    import 'package:flutter/material.dart';
    
    void main() => runApp(new MyApp());
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: new Scaffold(
            resizeToAvoidBottomPadding: false,
            appBar: new AppBar(
              title: new Text("test"),
            ),
            body: new Container(
              decoration: new BoxDecoration(
                image: new DecorationImage(
                  colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.dstATop),
                  image: new AssetImage("assets/images/keyboard.jpg"),
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
        );
      }
    }
    

提交回复
热议问题