我和我的伴侣正在从事一个扑朔迷离的项目。我们都是新手,我们尝试了各种教程。我们面临的问题是,用户输入一组奖励名称,然后在对话框中输入奖励值(我们称其为yoodoos)。我希望这些值以列表的形式显示在其他页面中。我们不知道如何实现。
下面是在dialogs.dart文件中编写的代码
void popupDialog12(BuildContext context) {
TextEditingController c = new TextEditingController();
showDialog(
context: context,
builder: (context) {
return new WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)
),
title: Text("Step 1. Type the new reward"),
content: TextField (
maxLength: 60,
decoration: InputDecoration(
hintText: 'Max 60 characters.',
),
controller: c,
),
actions: <Widget>[
FlatButton(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
//return null;
},
),
FlatButton(
child: Text("Next"),
onPressed: () {
String input = c.text;
input = input.trim();
if(input.length == 0){
popupDialog11(context);
//return null;
}
else{
rewards.add(c.text);
popupDialog13(context);
}
},
)
],
),
);
},
);
}
void popupDialog13(BuildContext context){
TextEditingController c = new TextEditingController();
showDialog(
context: context,
builder: (context) {
return new WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)
),
title: Text("Step 2. Set Yoodoos"),
content: TextField (
keyboardType: TextInputType.number,
maxLength: 2,
decoration: InputDecoration(
hintText: 'min=1 and max=10',
),
controller: c,
),
actions: <Widget>[
FlatButton(
child: Text("Back"),
onPressed: () {
Navigator.pop(context);
rewards.removeLast();
},
),
FlatButton(
child: Text("Done"),
onPressed: () {
Navigator.pop(context);
Navigator.pop(context);
if(int.parse(c.text) <= 10 && int.parse(c.text) >0){
configs.yoodoos.add(int.parse(c.text));
}
else{
popupDialog14(context);
}
},
)
],
),
);
},
);
}
void popupDialog14(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return new WillPopScope(
onWillPop: () async => false,
child:AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)
),
title: Text("Yoodoo"),
content: Text("Please enter a number between 0 and 10"),
actions: <Widget>[
FlatButton(
child: Text("Got it!"),
onPressed: () {
Navigator.of(context).pop();
//Navigator.of(context).pop();
//acceptGroupName(context);
},
),
]
)
);
},
barrierDismissible: false
);
}
void popupDialog15(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return new WillPopScope(
onWillPop: () async => false,
child:AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)
),
title: Text("Yoodoo"),
content: Text("No rewards have been set"),
actions: <Widget>[
FlatButton(
child: Text("Got it!"),
onPressed: () {
Navigator.of(context).pop();
//Navigator.of(context).pop();
//acceptGroupName(context);
},
),
]
)
);
},
barrierDismissible: false
);
}
下面是configure_rewards.dart文件中的代码。这些值将从对话框中传递。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dialogues.dart';
var rewards = List();
var yoodoos = List();
class ConfigureRewards extends StatefulWidget{
_RewardScreen createState() => new _RewardScreen();
}
class _RewardScreen extends State<ConfigureRewards> {
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
automaticallyImplyLeading: false,
title: new Text("ADD GROUP",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
),
),
),
bottomNavigationBar: BottomAppBar(
//color: Colors.red,
child: Container(
height: 60,
alignment: Alignment.bottomCenter,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: InkWell(
child: Container(
padding: EdgeInsets.symmetric(vertical: 15),
alignment: Alignment.center,
child: Text(
'Delete a Reward',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500,
color: Colors.white),
),
decoration: BoxDecoration(
//borderRadius: BorderRadius.all(Radius.circular(5)),
color: Colors.black,
),
),
onTap: () {
if(rewards.isNotEmpty){
rewards.removeLast();
yoodoos.removeLast();
}
else{
popupDialog15(context);
}
},
),
),
SizedBox(
child: Divider(
color: Colors.white,
thickness: 100,
),
),
Expanded(
child: InkWell(
child: Container(
padding: EdgeInsets.symmetric(vertical: 15),
alignment: Alignment.center,
child: Text(
'Add a reward',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500,
color: Colors.white),
),
decoration: BoxDecoration(
//borderRadius: BorderRadius.all(Radius.circular(5)),
color: Colors.black,
),
),
onTap: () {
popupDialog12(context);
},
),
),
],
),
),
elevation: 0,
),
);
}
我需要逐步指南来了解如何显示列表。