有没有办法将资产图像用作文件。我需要一个文件,以便它可以用于使用 http 在 Internet 上进行测试。我已经尝试了 Stackoverflow.com 的一些答案(如何使用 image.file 加载图像)但收到错误“无法打开文件,(操作系统错误:没有这样的文件或目录,errno = 2)”。附加的代码行也给出了错误。
File f = File('images/myImage.jpg');
RaisedButton(
onPressed: ()=> showDialog(
context: context,
builder: (_) => Container(child: Image.file(f),)),
child: Text('Show Image'),)
Run Code Online (Sandbox Code Playgroud)
使用 Image.memory 小部件(有效)
Future<Null> myGetByte() async {
_byteData = await rootBundle.load('images/myImage.jpg');
}
/// called inside build function
Future<File> fileByte = myGetByte();
/// Show Image
Container(child: fileByte != null
? Image.memory(_byteData.buffer.asUint8List(_byteData.offsetInBytes, _
byteData.lengthInBytes))
: Text('No Image File'))),
Run Code Online (Sandbox Code Playgroud) 如何在showDialog()被解雇/处置后更新主页?似乎它没有onDispose()功能.
找到另一个可能的答案:'WillPopScope'可以帮助检测后退按钮是否被按下.
将在'showDialog'中使用的小部件,在其构建函数中,小部件可以包含在'return new WillPopScope(child:______,onWillPop:_______)中; 代码可以在'onWillPop'函数中运行.这可以更新下面的主页.
我遇到了这个例子来获取小部件的大小/位置:https : //medium.com/@diegoveloper/flutter-widget-size-and-position-b0a9ffed9407
我的代码有什么问题?
我收到错误:
The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 8566): The method 'findRenderObject' was called on null.
I/flutter ( 8566): Receiver: null
I/flutter ( 8566): Tried calling: findRenderObject()
Run Code Online (Sandbox Code Playgroud)
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: MyWidgetSizeTMP());
}
}
class MyWidgetSizeTMP extends StatefulWidget{
@override
MyWidgetSizeTMPState createState() {
return new MyWidgetSizeTMPState();
}
}
class MyWidgetSizeTMPState extends State<MyWidgetSizeTMP> {
//creating Key for red panel …Run Code Online (Sandbox Code Playgroud) 如何初始化地图内的列表?
Map<String,Map<int,List<String>>> myMapList = Map();
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
The method '[]' was called on null.
I/flutter (16433): Receiver: null
I/flutter (16433): Tried calling: [](9)
Run Code Online (Sandbox Code Playgroud) 在 Scaffold 中,如果使用“actions”参数,它将隐藏“endDrawer”。可以两者都显示吗?
var tmp = new Scaffold(
/// end drawer
endDrawer: Container(color: Colors.red,
child: Text('END DRAWER')),
appBar: new AppBar(
title: Text('Title'),
actions: <Widget>[
/// Cancel, Save
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: IconButton(
icon: Icon(Icons.clear,size: 24.0,),
onPressed: () => Navigator.pop(context), //cancelButton,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: IconButton(
icon: Icon(Icons.check_circle,size: 30.0,),
onPressed: () => Navigator.pop(context),
),)
],
),
body: new Container(color: Colors.amber,);
Run Code Online (Sandbox Code Playgroud) 是否可以写这样一行,在这行中我想更改一个变量值?
opacity: condition == true ? 1, stringName ='Steve' : 0
Run Code Online (Sandbox Code Playgroud) 我应该关注“运行”窗口中的以下消息吗?:
I/chatty ( 7764): uid=10079(com.homemy.myapp) Thread-67 identical 24 lines
Run Code Online (Sandbox Code Playgroud) 如何让方块响应手势检测器以围绕圆旋转方块。顺时针旋转应该从 0 到 360 正增加,逆时针旋转应该从 360 减少到 0。但这里它增加超过 360,并且也会低于 0 变为负值。而且对阻力的反应是不可预测的。
仅当 IT 检测到手势时,正方形才会旋转,而不是其后面的圆圈。
我不知道这是否是解决问题的方法。任何帮助将非常感激。我已经这样做好几天了。
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(new MyRotateApp());
}
class MyRotateApp extends StatefulWidget {
@override
MyRotateAppState createState() {
return new MyRotateAppState();
}
}
class MyRotateAppState extends State<MyRotateApp> {
double angleDelta;
String strDialAngle;
@override
void initState() {
angleDelta = -90.0; //start from top position
strDialAngle = 'Angle Text';
super.initState();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new …Run Code Online (Sandbox Code Playgroud) 我在 Firebase 存储中保存了一张图像。如何将图像文件的 URL 分配给文件?
有没有办法做到这一点:
File file = File(URL);
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用 http,但导致错误:“解析图像编解码器时抛出 FileSystemException:无法打开文件”
final http.Response responseData = await http.get(url);
Uint8List uint8list = responseData.bodyBytes;
File file = File.fromRawPath(uint8list);
Run Code Online (Sandbox Code Playgroud)
使用 Uint8list 具有有效数据,如使用下面所示的小部件时所见,但与上述代码一起使用时会出现错误 File.fromRawPath(unint8list)
Image.memory(uint8list);
Run Code Online (Sandbox Code Playgroud)
尝试使用 ImageProvider 但无法从中获取 File 对象:
ImageProvider imageProvider = NetworkImage(url);
Run Code Online (Sandbox Code Playgroud)