Flutter 颤振:应为1个位置参数,但找到0个
我正在做一个flift项目,它将body:widget与main.dart分离,并将它放在一个新的全州widget中,文件名为todu_list.dart。现在我试图将它调回main.dart文件Flutter 颤振:应为1个位置参数,但找到0个,flutter,dart,flutter-layout,flutter-test,Flutter,Dart,Flutter Layout,Flutter Test,我正在做一个flift项目,它将body:widget与main.dart分离,并将它放在一个新的全州widget中,文件名为todu_list.dart。现在我试图将它调回main.dart文件body:SingleChildScrollView(child:Lists()),,我收到了这个错误 1 positional argument(s) expected, but 0 found. Try adding the missing arguments. 我在StackOverFlow上遇
body:SingleChildScrollView(child:Lists()),
,我收到了这个错误
1 positional argument(s) expected, but 0 found.
Try adding the missing arguments.
我在StackOverFlow上遇到了很多类似的问题,我意识到我应该在括号内添加一个参数“()”,但我不知道我的列表小部件中的哪个函数应该在那里调用
下面是“列表”小部件代码
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import '../models/todus.dart';
import 'package:intl/intl.dart';
import 'package:sqflite/sqflite.dart';
import '../models/database_helper.dart';
class Lists extends StatefulWidget {
final Function addTx;
Lists(this.addTx);
@override
_ListsState createState() => _ListsState();
}
class _ListsState extends State<Lists> {
final dbHelper = DatabaseHelper.instance;
void _addNewTransaction(BuildContextcontext) {
showModalBottomSheet(
backgroundColor: Colors.white,
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(25.0))),
context: context,
builder: (_) {
return GestureDetector(
onTap: () {},
// Where i started the code pasting from
child: Padding(
padding: MediaQuery.of(context).viewInsets,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 0.000,
child: Container(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Title'),
controller: _titleController,
autofocus: true,
onSubmitted: null,
// onChanged: (val) {
// titleInput = val;
// },
),
TextField(
decoration: InputDecoration(labelText: 'Description'),
controller: _discriptionController,
onSubmitted: null,
// onChanged: (val) => amountInput = val,
),
Container(
height: 70,
child: Row(
children: [
Text(selectedDateAndTime == null
? 'No Date Choosen'
: DateFormat('MM/dd/yyyy HH:mm')
.format(selectedDateAndTime)
// : DateFormat.yMd()
// .format(_selectedDate),
),
FlatButton(
textColor: Theme.of(context).primaryColor,
child: Icon(Icons.calendar_today),
// onPressed: () async {
// var value = await _selectedTime();
// },
onPressed: () => _selectDayAndTimeL(context),
),
],
),
),
RaisedButton(
child: Text('Save Todo'),
color: Theme.of(context).primaryColor,
textColor: Theme.of(context).textTheme.button.color,
onPressed: _submitData,
),
],
),
),
),
),
),
);
},
);
}
final _titleController = TextEditingController();
final _discriptionController = TextEditingController();
var favorite;
// DateTime _selectedDate;
DateTime selectedDateAndTime;
@override
void dispose() {
super.dispose();
_discriptionController.dispose();
_titleController.dispose();
}
Future _selectDayAndTimeL(BuildContext context) async {
DateTime _selectedDay = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2021),
lastDate: DateTime(2030),
builder: (BuildContext context, Widget child) => child);
TimeOfDay _selectedTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if (_selectedDay != null && _selectedTime != null) {
//a little check
}
setState(() {
selectedDateAndTime = DateTime(
_selectedDay.year,
_selectedDay.month,
_selectedDay.day,
_selectedTime.hour,
_selectedTime.minute,
);
// _selectedDate = _selectedDay;
});
// print('...');
}
List<ItemLists> items = [
ItemLists(
title: 'Best Music of the Year',
description: 'Davido',
favorite: false,
),
ItemLists(
title: 'Best Album Cover design',
description: 'Brighter Press',
favorite: false,
),
void _submitData() {
// if (_amountController.text.isEmpty) {
// return;
// }
final enteredTitle = _titleController.text;
final enteredDescription = _discriptionController.text;
if (enteredTitle.isEmpty) {
return;
}
widget.addTx(
enteredTitle,
enteredDescription,
selectedDateAndTime,
);
Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
return SizedBox(
child: Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return Dismissible(
key: ObjectKey(items[index]),
background: Container(
color: Colors.red,
),
child: Card(
child: ListTile(
leading: new IconButton(
icon: Icon(
Icons.check,
color:
items[index].favorite ? Colors.green : Colors.grey,
),
tooltip: 'Add to Favorite',
onPressed: () {
setState(() {
items[index].favorite = !items[index].favorite;
});
}),
title: Text('${items[index].title}'),
subtitle: Text('${items[index].description}'),
trailing: IconButton(
icon: Icon(Icons.calendar_today),
onPressed: () => _selectDayAndTimeL(context),
),
)),
onDismissed: (direction) {
final String myTitle = items[index].title;
// Remove the item from the data source.
setState(() {
var deletedItems = items.removeAt(index);
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('$myTitle Deleted'),
action: SnackBarAction(
label: 'Undo',
onPressed: () => setState(
() => items.insert(index, deletedItems),
)),
),
);
});
});
},
itemCount: items.length,
),
),
);
floatingActionButton:
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _addNewTransaction(context),
backgroundColor: Colors.redAccent,
);
}
}
导入“包装:颤振/材料.省道”;
进口“包装:颤振/基础.dart”;
导入“../models/todus.dart”;
导入“包:intl/intl.dart”;
导入“包:sqflite/sqflite.dart”;
导入“../models/database_helper.dart”;
类列表扩展了StatefulWidget{
最终功能addTx;
列表(this.addTx);
@凌驾
_ListsState createState()=>\u ListsState();
}
类_ListsState扩展状态{
final dbHelper=DatabaseHelper.instance;
void\u addNewTransaction(BuildContextcontext){
showModalBottomSheet(
背景颜色:Colors.white,
是的,
形状:圆形矩形边框(
边界半径:边界半径。垂直(顶部:半径。圆形(25.0)),
上下文:上下文,
建筑商:(){
返回手势检测器(
onTap:(){},
//我从哪里开始粘贴代码的
孩子:填充(
填充:MediaQuery.of(context).viewInsets,
孩子:填充(
填充:常数边集全部(8.0),
孩子:卡片(
标高:0.000,
子:容器(
填充:边缘设置。全部(20),
子:列(
crossAxisAlignment:crossAxisAlignment.end,
mainAxisSize:mainAxisSize.min,
儿童:[
文本字段(
装饰:输入装饰(标签文本:“标题”),
控制器:\标题控制器,
自动对焦:对,
onSubmitted:null,
//一旦更改:(val){
//titleInput=val;
// },
),
文本字段(
装饰:输入装饰(标签文本:“说明”),
控制器:\描述控制器,
onSubmitted:null,
//一旦更改:(val)=>amountInput=val,
),
容器(
身高:70,
孩子:排(
儿童:[
文本(selectedDateAndTime==null
“无日期选择”
:DateFormat('MM/dd/yyyy HH:MM')
.格式(选择日期和时间)
//:DateFormat.yMd()
//.格式(_selectedDate),
),
扁平按钮(
textColor:Theme.of(context.primaryColor),
子项:图标(图标。日历),
//onPressed:()异步{
//var value=wait_selectedTime();
// },
按下时:()=>\u选择Day和Timel(上下文),
),
],
),
),
升起的按钮(
子项:文本('Save Todo'),
颜色:主题。背景。原色,
textColor:Theme.of(context).textTheme.button.color,
按下按钮:\ u提交数据,
),
],
),
),
),
),
),
);
},
);
}
最终_titleController=TextEditingController();
final _descriptioncontroller=TextEditingController();
我最喜欢的;
//日期时间\u选择日期;
日期时间选择日期和时间;
@凌驾
无效处置(){
super.dispose();
_descriptionController.dispose();
_titleController.dispose();
}
Future\u选择day和timel(BuildContext上下文)异步{
DateTime\u selectedDay=等待显示日期选择器(
上下文:上下文,
initialDate:DateTime.now(),
firstDate:DateTime(2021年),
最后日期:日期时间(2030年),
生成器:(BuildContext上下文,小部件子项)=>child);
TimeOfDay\u selectedTime=等待显示时间选择器(
上下文:上下文,
initialTime:TimeOfDay.now(),
);
如果(_selectedDay!=null&&u selectedTime!=null){
//小支票
}
设置状态(){
selectedDateAndTime=日期时间(
_选择日期。年份,
_选择日期、月份,
_选择的日期,
_选择time.hour,
_选择time.minute,
);
//_selectedDate=_selectedDay;
});
//印刷品(“…”);
}
列表项=[
项目列表(
标题:“年度最佳音乐”,
描述:'大卫',
最喜欢的:假,
),
项目列表(
标题:“最佳专辑封面设计”,
描述:'Brighter Press',
最喜欢的:假,
),
void _submitData(){
//if(_amountController.text.isEmpty){
//返回;
// }
最终输入标题=_titleController.text;
最终输入的描述=\u descriptioncontroller.text;
如果(输入标题isEmpty){
返回;
}
widget.addTx(
题记:,
输入描述,
选择日期和时间,
);
Navigator.of(context.pop();
}
@凌驾
小部件构建(BuildContext上下文)
widget.addTx(
enteredTitle,
enteredDescription,
selectedDateAndTime,
);
void addTitleDescDate(string title, string description, string date) { // NB you should probably use a Date object or epoch time.
print(title);
print(description);
print(date);
}