1

在此处输入图像描述尝试将神社应用程序迁移到颤振网络,但是当迁移无法在localhost显示图像(放置在资产文件夹中的神社徽标)时,包含图像的断言文件夹被放置在 web 文件夹中,如Flutter Web 迁移指南中所述并更新了飞镖具有正确路径的代码,但它仍然不显示图像。

请提供解决方案谢谢!

资产路径图片

登录.dart

import 'package:flutter_web/material.dart';

    class LoginPage extends StatefulWidget {
      @override
      _LoginPageState createState() => _LoginPageState();
    }

    class _LoginPageState extends State<LoginPage> {
      // TODO: Add text editing controllers (101)
      final _usernameController = TextEditingController();
      final _passwordController = TextEditingController();
      // TODO: Add text editing controllers (101)
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: SafeArea(
            child: ListView(
              padding: EdgeInsets.symmetric(horizontal: 24.0),
              children: <Widget>[
                SizedBox(height: 80.0),
                Column(
                  children: <Widget>[
                    Image.asset('web/assets/diamond.png'),
                    SizedBox(height: 16.0),
                    Text('SHRINE'),
                  ],
                ),
                SizedBox(height: 120.0),
                // TODO: Wrap Username with AccentColorOverride (103)
                // TODO: Remove filled: true values (103)
                // TODO: Wrap Password with AccentColorOverride (103)
                // TODO: Add TextField widgets (101)
                // [Name]
                TextField(
                  controller: _usernameController,
                  decoration: InputDecoration(
                      filled: true,
                      border: OutlineInputBorder(),
                      labelText: 'Username'),
                ),
                SizedBox(
                  height: 12.0,
                ),
                // [Password]
                TextField(
                  controller: _passwordController,
                  decoration: InputDecoration(
                    filled: true,
                    border: OutlineInputBorder(),
                    labelText: 'Password',
                  ),
                  obscureText: true,
                ),
                // TODO: Add button bar (101)
                ButtonBar(
                  children: <Widget>[
                    // Todo Add buttons (101)
                    RaisedButton(
                      child: Text('Cancel'),
                        onPressed: () {
                          // TODO: Clear the text fields (101)
                          _usernameController.clear();
                          _passwordController.clear();
                        }
                    ),
                    // TODO: Add an elevation to NEXT (103)
                    // TODO: Add a beveled rectangular border to NEXT (103)
                    RaisedButton(
                      child: Text('NEXT'),
                      onPressed: () {
                        // TODO: Show the next page (101)
                        Navigator.pop(context);
                      },
                    ),
                  ],
                ),
              ],
            ),
          ),
        );[enter image description here][1]
      }
    }

    // TODO: Add AccentColorOverride (103)
4

1 回答 1

2

需要直接定义asset,不用在**flutter web preview中定义它的路径**

Image.asset('diamond.png')
于 2019-05-20T11:08:11.713 回答