Flutter 获取太多位置参数时出错
位置参数是如何工作的Flutter 获取太多位置参数时出错,flutter,dart,Flutter,Dart,位置参数是如何工作的 children: <Widget>[ Table( children: [ _buildTableRow( 'one', 'two', 'Three' ), ], ), ], 仅接受一个字符串 在您的代码中 您传递三个字符串 _buildTableRow( 'one', 'two', 'Three' ), 你可以这样做 _buil
children: <Widget>[
Table(
children: [
_buildTableRow(
'one',
'two',
'Three'
),
],
),
],
仅接受一个字符串在您的代码中
您传递三个字符串
_buildTableRow(
'one',
'two',
'Three'
),
你可以这样做
_buildTableRow("one, two, Three")
完整代码
import 'package:flutter/material.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(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: BasicTable(),
);
}
}
class BasicTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Table Widget")),
body: Table(
defaultColumnWidth: FixedColumnWidth(150.0),
border: TableBorder(
horizontalInside: BorderSide(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0,
),
verticalInside: BorderSide(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0,
),
),
children: [
_buildTableRow("one, two, three"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
],
),
);
}
TableRow _buildTableRow(String listOfNames) {
return TableRow(
children: listOfNames.split(',').map((name) {
return Container(
alignment: Alignment.center,
child: Text(name, style: TextStyle(fontSize: 20.0)),
padding: EdgeInsets.all(8.0),
);
}).toList(),
);
}
}
然后像这样使用它:
_buildTableRow('one,two,Three')
嗨,警察路。关于这一点,我可以请你在CW答案中留下归属信息吗?它已经在Meta和SO CVR中讨论过。我认为大家的共识是,只有明确内容的作者,才能满足许可条件。如果您想阅读,我可以为您挖掘一个链接。@halfer您好,另一个用户(diegoveloper)已经提供了相同的答案,您提到“代表问题作者发布解决方案,将其从问题中移除”,但是OP更新了他的帖子(在该用户在评论中写道如何解决它之后),OP更新了帖子,那个用户把它写成了答案。希望我能澄清这一点。你上面的描述不是特别清楚,但读了几遍之后,我想我明白你的意思了——原始作者来自diegoveloper,而不是BloodLoss(OP),因此不需要归属。我不确定我是否同意,但正确的做法是不编辑这篇文章,并要求将其删除。(也许你确实要求删除它,因为有版主删除了它)。最后,我的主要观点是,如果你看到署名是故意添加的,最好不要删除它。在Meta上。@halfer是的,你明白我的意思了(即使我现在读它,我在第一次尝试lol时也没有弄清楚),很抱歉我以前不知道
属性。
import 'package:flutter/material.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(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: BasicTable(),
);
}
}
class BasicTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Table Widget")),
body: Table(
defaultColumnWidth: FixedColumnWidth(150.0),
border: TableBorder(
horizontalInside: BorderSide(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0,
),
verticalInside: BorderSide(
color: Colors.black,
style: BorderStyle.solid,
width: 1.0,
),
),
children: [
_buildTableRow("one, two, three"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
_buildTableRow("Inducesmile.com, Google.com, Flutter.dev"),
],
),
);
}
TableRow _buildTableRow(String listOfNames) {
return TableRow(
children: listOfNames.split(',').map((name) {
return Container(
alignment: Alignment.center,
child: Text(name, style: TextStyle(fontSize: 20.0)),
padding: EdgeInsets.all(8.0),
);
}).toList(),
);
}
}
TableRow _buildTableRow(String listOfNames) {
return TableRow(
children: listOfNames.split(',').map((name) {
return Container(child: Text(name));
}).toList(),
);
}
_buildTableRow('one,two,Three')