【发布时间】:2020-01-10 10:08:06
【问题描述】:
我尝试使用外部小部件 (https://github.com/sarbagyastha/flutter_tagging)。我知道,它的保证适用于 android 版本。但是我在 Web 版本中添加它并得到错误“参数类型'FlutterTagging 不能分配给参数类型 Widget`”。它只是简单的代码(例如“Hello, World”,仅此而已)。是不是应该在网页版上工作?
主要代码继承自Widget - 类,源代码清晰。而且我不知道那个错误是什么意思。
import 'package:flutter_web/material.dart';
import 'package:flutter_tagging/flutter_tagging.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, World!',
),
SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child:
FlutterTagging(
textFieldDecoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "Tags",
labelText: "Enter tags"),
addButtonWidget: _buildAddButton(),
chipsColor: Colors.pinkAccent,
chipsFontColor: Colors.white,
deleteIcon: Icon(Icons.cancel,color: Colors.white),
chipsPadding: EdgeInsets.all(2.0),
chipsFontSize: 14.0,
chipsSpacing: 5.0,
chipsFontFamily: 'helvetica_neue_light',
suggestionsCallback: (pattern) async {
return await TagSearchService.getSuggestions(pattern);
},
onChanged: (result) {
setState(() {
text = result.toString();
});
},
),
),
SizedBox(
height: 20.0,
),
Center(
child: Text(
'test',
style: TextStyle(color: Colors.pink),
),
)
],
),
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Widget _buildAddButton() {
return Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Colors.pinkAccent,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
Icons.add,
color: Colors.white,
size: 15.0,
),
Text(
"Add New Tag",
style: TextStyle(color: Colors.white, fontSize: 14.0),
),
],
),
);
}
【问题讨论】:
-
Flutter 1.9.1+hotfix.1 • 频道测试版 • github.com/flutter/flutter.git 框架 • 修订版 a1fb3fabec(4 天前) • 2019-09-03 18:07:52 -0700 引擎 • 修订版 cc88fa45db 工具• Dart 2.5.0 Flutter Doctor - 好的。
标签: flutter flutter-web