Flutter -Lanaging_tool如何导入类
我对颤振没有太多经验。
我想使用 Dart 和 Flutter 的 language_tool 库。(https://pub.dev/packages/language_tool< /a>)
我创建了下面的脚本,并希望包含所有 .issueTypes 的 ListTile 出现在屏幕上。
但我不知道如何从 language_tool 包中导入writingMistake 类。
你知道我该如何解决吗?
void main() => runApp(mainApp());
class mainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Chat(),
);
}
}
class Chat extends StatefulWidget {
const Chat({Key? key}) : super(key: key);
@override
_ChatState createState() => _ChatState();
}
class _ChatState extends State<Chat> {
String text = 'Helllo I am Gabriele';
Future<List<WritingMistake>> tool(String text) async {
var tool = LanguageTool();
var result = tool.check(text);
var correction = await result;
print(correction);
List<WritingMistake> mistakes = [];
for (var m in correction) {
WritingMistake mistake = WritingMistake(m['offset'], m['length'],
m['issueType'], m['issueDescription'], m['replacements']);
mistakes.add(mistake);
}
print(mistakes.length);
return mistakes;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: FutureBuilder(
future: tool(text),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: Text('Loading...'),
),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(snapshot.data[index].issueType),
);
},
);
}
},
),
),
);
}
}
希望有人能帮助我。谢谢。
I don't have much experience with flutter.
I would like to use the language_tool library for Dart and Flutter .(https://pub.dev/packages/language_tool)
I created the script below and would like a ListTile with all the .issueTypes to appear on the screen.
But I don't know how to import the WritingMistake class from the language_tool package.
Do you know how I can solve?
void main() => runApp(mainApp());
class mainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Chat(),
);
}
}
class Chat extends StatefulWidget {
const Chat({Key? key}) : super(key: key);
@override
_ChatState createState() => _ChatState();
}
class _ChatState extends State<Chat> {
String text = 'Helllo I am Gabriele';
Future<List<WritingMistake>> tool(String text) async {
var tool = LanguageTool();
var result = tool.check(text);
var correction = await result;
print(correction);
List<WritingMistake> mistakes = [];
for (var m in correction) {
WritingMistake mistake = WritingMistake(m['offset'], m['length'],
m['issueType'], m['issueDescription'], m['replacements']);
mistakes.add(mistake);
}
print(mistakes.length);
return mistakes;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: FutureBuilder(
future: tool(text),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: Text('Loading...'),
),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(snapshot.data[index].issueType),
);
},
);
}
},
),
),
);
}
}
Hope someone can help me. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我下载了软件包,复制了您的代码,在该行中只有一个错误:
我使用此代码解决了它:
程序输出:
如果我更改短语:
am gabriele“
“你好我是gabriele”
,然后输出将“未分类”。希望这有帮助!
I downloaded the package, copied your code, I got only one error, in the line:
And I solved it with this code:
Program Output:
If I change the phrase:
"Helllo I am Gabriele"
to"Hello I am Gabriele"
, then the output will be "uncategorized".Hope this helped!