Flutter 如何显示依赖于颤振中另一个字符串数据的数据?
我有两个选择框,显示一个AlertDialog。第一个在alertdialog中显示listview.builder,选项为“Havo”或“Vwo”。当用户选择Havo时,选项1-5必须显示在第二个警报对话框中。当用户选择Vwo时,选项1-6必须显示在第二个alertdialog中 这是我保存数据的列表: (同时保存其他数据,请忽略) 这就是我的代码的构建方式:Flutter 如何显示依赖于颤振中另一个字符串数据的数据?,flutter,dart,Flutter,Dart,我有两个选择框,显示一个AlertDialog。第一个在alertdialog中显示listview.builder,选项为“Havo”或“Vwo”。当用户选择Havo时,选项1-5必须显示在第二个警报对话框中。当用户选择Vwo时,选项1-6必须显示在第二个alertdialog中 这是我保存数据的列表: (同时保存其他数据,请忽略) 这就是我的代码的构建方式: import 'package:flutter/material.dart'; import '../..
import 'package:flutter/material.dart';
import '../../models/studyOptionsModel.dart';
class SetupScreenThreeForm extends StatefulWidget {
@override
_SetupScreenThreeFormState createState() => _SetupScreenThreeFormState();
}
class _SetupScreenThreeFormState extends State<SetupScreenThreeForm> {
final _formKey = GlobalKey<FormState>();
var _isLoginPage = false;
var _schoolLevel = 'Niveau';
var _classYear = 'Klas';
var _bestSubjects = '';
var selectionOptions = LEVELS.toList();
//The alertdialog for setting the level
createAlertDialog(BuildContext context, selectionType) {
return showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
backgroundColor: Color(0xFF7E36EC),
child: ListView.builder(
shrinkWrap: true,
itemCount: selectionOptions.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_schoolLevel = selectionOptions[index].level;
print(_schoolLevel);
Navigator.pop(context);
});
},
child: ListTile(
leading: Text(
selectionOptions[index].level,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
))),
],
),
);
},
));
});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_schoolLevel,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'level');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_classYear,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'years');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Minst sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
)
],
)
]);
}
}
导入“包装:颤振/材料.省道”;
导入“../models/studyOptionsModel.dart”;
类SetupScreenThreeForm扩展StatefulWidget{
@凌驾
_SetupScreenThreeFormState createState()=>\u SetupScreenThreeFormState();
}
类_SetupScreenThreeFormState扩展状态{
final _formKey=GlobalKey();
var_isLoginPage=false;
var_学校级别=‘Niveau’;
var_classYear='Klas';
var_bestSubjects='';
var selectionOptions=LEVELS.toList();
//用于设置级别的alertdialog
createAlertDialog(BuildContext上下文,selectionType){
返回显示对话框(
上下文:上下文,
生成器:(上下文){
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(20)),
背景颜色:颜色(0xFF7E36EC),
子项:ListView.builder(
收缩膜:对,
itemCount:selectionOptions.length,
itemBuilder:(上下文,索引){
返回填充(
填充:常数边集全部(8.0),
子:列(
儿童:[
墨水池(
onTap:(){
设置状态(){
_学校级别=选择选项[索引]。级别;
印刷品(学校级);
Navigator.pop(上下文);
});
},
孩子:ListTile(
前导:文本(
选择选项[索引]。级别,
样式:TextStyle(
颜色:颜色,白色,
fontFamily:“罂粟花”,
fontWeight:fontWeight.w500,
尺寸:14),,
))),
],
),
);
},
));
});
}
@凌驾
小部件构建(构建上下文){
返回列(
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
纵队(
mainAxisSize:mainAxisSize.min,
儿童:[
大小盒子(
身高:20,
),
容器(
宽度:double.infinity,
身高:50,
孩子:InkWell(
孩子:升起按钮(
形状:圆形矩形边框(
边界半径:边界半径。圆形(25)),
颜色:颜色(0xFF7E36EC),
子对象:对齐(
对齐:alignment.centerLeft,
子:文本(
_学校层面,
样式:TextStyle(
颜色:颜色,白色,
fontFamily:“罂粟花”,
fontWeight:fontWeight.w500,
尺寸:14),,
),
),
已按下:(){
createAlertDialog(上下文“级别”);
},
),
),
),
大小盒子(
身高:20,
),
容器(
宽度:double.infinity,
身高:50,
孩子:InkWell(
孩子:升起按钮(
形状:圆形矩形边框(
边界半径:边界半径。圆形(25)),
颜色:颜色(0xFF7E36EC),
子对象:对齐(
对齐:alignment.centerLeft,
子:文本(
_学年,
样式:TextStyle(
颜色:颜色,白色,
fontFamily:“罂粟花”,
fontWeight:fontWeight.w500,
尺寸:14),,
),
),
已按下:(){
createAlertDialog(上下文“年”);
},
),
),
),
大小盒子(
身高:20,
),
容器(
宽度:double.infinity,
身高:50,
孩子:InkWell(
孩子:升起按钮(
形状:圆形矩形边框(
边界半径:边界半径。圆形(25)),
颜色:颜色(0xFF212121),
子对象:对齐(
对齐:alignment.centerLeft,
子:文本(
“Sterkste vakken”,
样式:TextStyle(
颜色:颜色,白色,
fontFamily:“罂粟花”,
fontWeight:fontWeight.w500,
尺寸:14),,
import 'package:flutter/material.dart';
import '../../models/studyOptionsModel.dart';
class SetupScreenThreeForm extends StatefulWidget {
@override
_SetupScreenThreeFormState createState() => _SetupScreenThreeFormState();
}
class _SetupScreenThreeFormState extends State<SetupScreenThreeForm> {
final _formKey = GlobalKey<FormState>();
var _isLoginPage = false;
var _schoolLevel = 'Niveau';
var _classYear = 'Klas';
var _bestSubjects = '';
var selectionOptions = LEVELS.toList();
//The alertdialog for setting the level
createAlertDialog(BuildContext context, selectionType) {
return showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
backgroundColor: Color(0xFF7E36EC),
child: ListView.builder(
shrinkWrap: true,
itemCount: selectionOptions.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_schoolLevel = selectionOptions[index].level;
print(_schoolLevel);
Navigator.pop(context);
});
},
child: ListTile(
leading: Text(
selectionOptions[index].level,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
))),
],
),
);
},
));
});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_schoolLevel,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'level');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_classYear,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'years');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Minst sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
)
],
)
]);
}
}
if (userselection=='Havo'){
LEVELS.length(x) //x is the number of levels you want to show for example for 4 levels x=3
}