Я получаю следующую ошибку, когда пытаюсь использовать чернильницу
No Material widget found.
InkWell widgets require a Material widget ancestor.
In material design, ....
The specific widget that could not find a Material ancestor was:
InkWell
The ancestors of this widget were:
...
Column
TextOnCanvasWidget
RepaintBoundary
IndexedSemantics
NotificationListener<KeepAliveNotification>
...
The relevant error-causing widget was:
InkWell
Я знаю, что мне нужно использовать дизайн материала в качестве предка, чтобы использовать чернильницу ... но я думаю, что я ... .
Тем не менее, в трассировке показано, что мое дерево предков - это Column-> TextOnCanvasWidget-> RepaintBoundary ..
Наверное, я запутался, почему мой виджет материала не отображается в моем дереве предков. когда мой верхний модуль - MaterialApp.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TextOnCanvasList(),
);
}
}
class TextOnCanvasList extends StatelessWidget {
final List<String> listOfNames = [
"Matt",
"John",
"Bill123456",
"Doug",
"Paul",
"Hanz",
"Ruby",
"Karl",
"WOW123456789",
"HAL",
"TODD",
"MARK",
"CURT"
];
@override
Widget build(BuildContext context) {
return SafeArea(
child: ListView.builder(
scrollDirection: Axis.horizontal,
reverse: false,
itemBuilder: (_, int index) =>
TextOnCanvasWidget(this.listOfNames[index]),
itemCount: listOfNames.length,
),
);
}
}
class TextOnCanvasWidget extends StatelessWidget {
final String name;
TextOnCanvasWidget(this.name);
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
InkWell(
onTap: () {
print("You Tapped: " + this.name);
},
child: new CustomPaint(
size: Size(52, 0),
foregroundPainter: new TextOnCanvasPainter(this.name),
),
),
],
);
}
}
class TextOnCanvasPainter extends CustomPainter {
final String name;
TextOnCanvasPainter(this.name);
static const l0 = 50.0;
static final l1 = 10.0;
static final h = 30.0;
final Path chevron = new Path()
..relativeLineTo(l0, 0)
..relativeLineTo(l1, h / 2)
..relativeLineTo(-l1, h / 2)
..relativeLineTo(-l0, 0)
..relativeLineTo(l1, -h / 2)
..close();
void paint(Canvas canvas, Size size) {
Paint fillShape = new Paint()
..color = Colors.blue
..style = PaintingStyle.fill
..strokeWidth = 2.0;
TextSpan span = new TextSpan(
style: new TextStyle(color: Colors.red[600]),
text: this.name,
);
TextPainter tp = new TextPainter(
text: span,
textAlign: TextAlign.left,
textDirection: TextDirection.ltr);
tp.layout(minWidth: 500.0);
canvas.drawPath(chevron, fillShape);
tp.paint(canvas, new Offset(l1, h / 8));
canvas.save();
canvas.restore();
}
@override
bool shouldRepaint(TextOnCanvasPainter oldDelegate) => true;
}