我正在处理浮动操作栏,由于在看板类中,我的_show方法是私有的,因此无法访问它。我尝试过转换为静态,但是我的数据库相关方法导致了问题。我不知道该怎么做?
这是我要访问的班级
import 'package:flutter/material.dart';
import 'package:entrecor/Util/KanbanScreen.dart' ;
class HomePage extends StatelessWidget {
....
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Welcome'),
actions: <Widget>[
FlatButton(
child: Text('Logout',
style: TextStyle(fontSize: 17.0, color: Colors.white)),
onPressed: () => _signOut(context)),
],
),
body: Tabs(),
floatingActionButton:Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
heroTag: 'FAB1',
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => NotePage()),
);
},
tooltip: 'Add Note',
child: Icon(Icons.note_add),
),
FloatingActionButton(
heroTag: 'FAB2',
child: Icon(Icons.share,color: Colors.white,),
onPressed: _showFormDialog,
),
],
)
);
}
}
这是我想从中访问的课程
import 'package:entrecor/Model/todoitem.dart';
import 'package:entrecor/Util/database_client.dart';
import 'package:entrecor/Util/dateformatter.dart';
import 'package:flutter/material.dart';
class KanbanScreen extends StatefulWidget {
@override
_KanbanScreenState createState() => _KanbanScreenState();
}
class _KanbanScreenState extends State<KanbanScreen> {
final TextEditingController _textEditingController =
new TextEditingController();
var db = new DatabaseHelper();
final List<TODOItem> _itemList = <TODOItem>[];
@override
void initState() {
super.initState();
_readToDoList();
}
void _handleSubmitted(String text) async {
_textEditingController.clear();
TODOItem todoItem = new TODOItem(text, dateFormatted());
int savedItemId = await db.saveItem(todoItem);
TODOItem addedItem = await db.getItem(savedItemId);
setState(() {
_itemList.insert(0, addedItem);
});
print("Item saved id: $savedItemId");
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
new Flexible(
child: ListView.builder(
padding: EdgeInsets.all(8.0),
reverse: false,
itemCount: _itemList.length,
itemBuilder: (__, int index) {
return Card(
color: Colors.black12,
child: new ListTile(
title: _itemList[index],
onLongPress: () => _updateItem(_itemList[index], index),
trailing: new Listener(
key: new Key(_itemList[index].itemName),
child: Icon(
Icons.remove_circle,
color: Colors.redAccent,
),
onPointerDown: (pointerEvent) =>
_deleteToDo(_itemList[index].id, index),
),
),
);
},
),
),
new Divider(
height: 1.0,
)
],
),
floatingActionButton: FloatingActionButton(
tooltip: "Add Item",
child: ListTile(
title: Icon(Icons.add), //Basiicaly ı want
this in home class
),
onPressed: _showFormDialog,
),
);
}
void _showFormDialog() {
var alert = new AlertDialog(
content: Row(
children: <Widget>[
new Expanded(
child: new TextField(
controller: _textEditingController,
autofocus: true,
decoration: InputDecoration(
labelText: "Item",
hintText: "eg. Just Do It",
icon: Icon(Icons.note_add)),
),
)
],
),
actions: <Widget>[
new FlatButton(
onPressed: () {
_handleSubmitted(_textEditingController.text);
_textEditingController.clear();
Navigator.pop(context);
},
child: Text("Save"),
),
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text("Cancel"),
)
],
);
void _handleSubmittedUpdate(int index, TODOItem item) {
setState(() {
_itemList.removeWhere((element) {
_itemList[index].itemName == item.itemName;
});
});
}
...
}
答案 0 :(得分:1)
您的方法是否非私有-将_show
重命名为show
。
如果您的方法,字段或类名以_
-符号开头-它们是私有的