我是新手。 我想连续放置一个进度条(用custompainter制作),但是我不知道该怎么做。我希望该行的所有元素都对齐,垂直居中,并且它们之间的间距相等。
我的代码是:
import requests
overpass_query = """
[out:json][timeout:600];
{{geocodeArea:Niedersachsen}}->.searchArea;
(
node[place=city](area.searchArea);
node[place=town](area.searchArea);
);
out;
"""
overpass_url = "http://overpass-api.de/api/interpreter"
response = requests.get(overpass_url, params={'data': overpass_query})
data = response.json()
/home/enno/events/docker/etl/venv/bin/python /home/enno/events/docker/etl/test2.py
Traceback (most recent call last):
File "/home/enno/events/docker/etl/test2.py", line 16, in <module>
data = response.json()
File "/home/enno/events/docker/etl/venv/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Process finished with exit code 1
和:
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(alignment: Alignment.center, child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('text1'),
Text('text2'),
CustomPaint(painter: progressBar(),),
Text('text3'),
Text('text4')
],
),)
));
答案 0 :(得分:2)
在当前代码中,CustommPaint的大小为0。CustomPaint的documentation提到了其大小的获取方式,因此您需要为孩子提供size或提供其size属性(例如size:Size( 50,14))。同样在绘画方法中,您应该使用Size参数,以便仅在可用的空间中绘制,而不会越过边界(就像您当前所做的那样):
canvas.drawRRect(RRect.fromRectAndRadius(Rect.fromLTWH(0, 0, size.width, size.height), corner), paint);