Closed sleepreading closed 3 years ago
@sleepreading Thanks for the report! I couldn't reproduce the issue locally, but got a potential fix for it. Mind to check if it got resolved in version 2.0.1
https://pub.dev/packages/scratcher ?
Had same issue. Change widgets.dart line (around line number 127) from:
image: snapshot.data
to
image: widget.image == null ? null : snapshot.data,
To solve the issue I would need a reproducible example (gist/repo/snippet). I cannot reproduce the issue by simply passing down image: null
https://github.com/vintage/scratcher/blob/master/example/lib/basic.dart#L70
Closing it due to inactivity.
@vintage sorry for responsing too late
///
/// https://github.com/vintage/scratcher
///
class ScratcherDemo extends StatefulWidget {
ScratcherDemo({Key? key}) : super(key: key);
static const String routeName = "/scratch";
static const String title = "刮刮卡";
static const String url = "https://pub.flutter-io.cn/packages/scratcher";
@override
_ScratcherDemoState createState() => _ScratcherDemoState();
}
class _ScratcherDemoState extends State<ScratcherDemo> {
final scratchKey = GlobalKey<ScratcherState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("scratcher"),
actions: <Widget>[PluginButton(ScratcherDemo.title, ScratcherDemo.url)],
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ListTile(title: Text("默认用法")),
Center(
child: Scratcher(
brushSize: 30,
threshold: 50,
color: Colors.grey,
// image: Image.asset('assets/images/avatar_bk.jpg'), // <--- comment this line would reproduce the issue
onChange: (value) {
debugPrint("当前刮开比例: $value%");
},
onThreshold: () {
debugPrint("已触发设置的全部刮开阈值");
},
child: Container(
height: 300,
width: 300,
color: Colors.blue,
),
),
),
Container(
height: 20.pt,
),
ListTile(title: Text("自定义")),
Center(
child: Scratcher(
key: scratchKey,
brushSize: 30.pt,
threshold: 50,
color: Colors.pink,
image: Image.asset('assets/images/avatar_bk.jpg'),
onChange: (value) {
debugPrint("当前刮开比例: $value%");
},
onThreshold: () {
debugPrint("已触发设置的全部刮开阈值");
scratchKey.currentState!.reveal(duration: Duration(milliseconds: 500));
},
child: Container(
width: 300.pt,
height: 150.pt,
child: ImageUtil.load(
'assets/images/avatar.jpg',
fit: BoxFit.cover,
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text("重置"),
onPressed: () {
scratchKey.currentState!.reset();
},
),
RaisedButton(
child: Text("刮开"),
onPressed: () {
scratchKey.currentState!.reveal(duration: Duration(milliseconds: 500));
},
)
],
)
],
),
),
);
}
}
I had the same issue. The _imageLoader
has a nullable type but the completer was created without the nullable type. I created a PR which solves this #31
The fix will be included in the next release. In the meantime feel free to use github version :+1:
2.1.0
has been just released https://pub.dev/packages/scratcher
result:
I found the problem code here:
environment: