请,我要传递数据(ItemList中的索引和列表到StatefulWidget中的FloatingActionButton)
class _mes_adresseState extends State<mes_adresse> {
DatabaseHelper databaseHelper = new DatabaseHelper();
_save(String token) async {
final prefs = await SharedPreferences.getInstance();
final key = 'token';
final value = token;
prefs.setString(key, value);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
floatingActionButton: FloatingActionButton.extended(
backgroundColor: Colors.amber,
onPressed: () {Navigator.of(context).push(
new MaterialPageRoute(
builder: (BuildContext context) => new EditAdress(
index: i // from index in list view.builder ,
list : list // from list in itemlist,
)),
class ItemList extends StatelessWidget {
List list;
ItemList({this.list});
@override
Widget build(BuildContext context) {
return new ListView.builder(
itemCount: list[0] == null ? 0 : list[0].length,
itemBuilder: (context, i) {
return new Container(
padding: const EdgeInsets.all(1.0),
child: new GestureDetector(
onTap: () => Navigator.of(context).push(
new MaterialPageRoute(
builder: (BuildContext context) => new EditAdress(
list: list,
index: i,
)),
// builder: (BuildContext context) => new ShowData(list:list , index:i,) ),
),
);},
floatingActionButton返回另一个页面,并具有mes_adresse页面的列表和索引
答案 0 :(得分:0)
您需要在目标类的构造函数中声明变量;
class EditAdress extends StatefulWidget {
final List list;
final int index;
const EditAdress({Key key, this.list, this.index}) : super(key: key);
@override
_EditAdressState createState() => _EditAdressState();
}
class _EditAdressState extends State<EditAdress> {
@override
Widget build(BuildContext context) {
// you can access your data through widget
print(widget.index);
return Container(
);
}
}