我正在尝试使用资产图像/网络图像创建自定义标记。我拍摄该图像并创建一个小部件以进行必要的样式设置,然后尝试调用返回MarkerGenerator的List<Uint8List>
MarkerGenerator。但我得到了Uint8List
没有资产图像。我认为资产图像的渲染在调用 MarkerGenerator 之前还没有完成。渲染assetImage完成后如何调用MarkerGenerator。
import 'dart:typed_data';
import 'marker_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class MyMarkerPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyMarkerPageState();
}
}
class _MyMarkerPageState extends State<MyMarkerPage> {
Uint8List imageInMemory;
List<Uint8List> markerImage;
@override
void initState() {
super.initState();
List<Widget> widgetList = new List();
for (int i = 0; i < 1; i++) {
widgetList.add(
Container(
height: 50,
width: 50,
padding: EdgeInsets.all(10),
color: Colors.green,
child: Image.asset("assets/myImage.jpg"),
),
);
}
MarkerGenerator(widgetList, (bitmaps) {
setState(() {
markerImage = bitmaps;
});
}).generate(context);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Widget To Image'),
),
body: SingleChildScrollView(
child: Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
markerImage != null
? Container(
child: Image.memory(markerImage[0]),
margin: EdgeInsets.all(10))
: Container(),
],
),
),
),
);
}
}