gpt4 book ai didi

dart - 如何在将 flutter 应用程序迁移到 flutter web 时显示图像 Assets ?

转载 作者:IT王子 更新时间:2023-10-29 07:19:44 24 4
gpt4 key购买 nike

enter image description here 尝试将 shrine 应用程序迁移到 flutter web 但迁移时无法在 localhost 显示图像(shrine Logo 放置在 assets 文件夹中),包含图像的 asserts 文件夹放置在 web 文件夹中在 Flutter Web migration guide 中进行了解释,并使用正确的路径更新了 dart 代码,但它仍然不显示图像。

请提供解决方案谢谢!

assets path image

登录.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)

最佳答案

需要直接定义asset,不用在**中定义asset的路径 flutter 网页预览**

Image.asset('diamond.png')

关于dart - 如何在将 flutter 应用程序迁移到 flutter web 时显示图像 Assets ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56217498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com