android - 我以后可以使用列表项中的文本吗?
问题描述
所以我的问题可能没有总结出我想要做的很好。在 Stack -> Padding 中,目前我有名为“$zoneName”的文本。我正在尝试获取它,以便显示输入区域 (zero_one, zero_two) 的 imageurl,以便它与相关索引匹配。现在它写得有点“古怪”,因为我尝试了一些不同的东西,但我认为理解我所问内容的结构就在那里。
import 'package:arknights_random_app/pages/griditemmap.dart';
import 'package:flutter/material.dart';
import 'package:arknights_random_app/pages/maps.dart';
class MapSelection extends StatefulWidget {
@override
_MapSelectionState createState() => _MapSelectionState();
}
class _MapSelectionState extends State<MapSelection> {
List<Zone> itemZoneList;
List<Zone> selectedZoneList;
var zoneName = '$imageurl';
Card card;
@override
void initState() {
loadList();
super.initState();
}
loadList() {
itemZoneList = List();
selectedZoneList = List();
itemZoneList.add(Zone(zero_one, 1));
itemZoneList.add(Zone(zero_two, 2));
itemZoneList.add(Zone(zero_three, 3));
itemZoneList.add(Zone(zero_four, 4));
itemZoneList.add(Zone(zero_five, 5));
itemZoneList.add(Zone(zero_six, 6));
itemZoneList.add(Zone(zero_seven, 7));
itemZoneList.add(Zone(zero_eight, 8));
itemZoneList.add(Zone(zero_nine, 9));
itemZoneList.add(Zone(zero_ten, 10));
itemZoneList.add(Zone(zero_eleven, 11));
// selectedMapList.addAll(itemMapList);
}
@override
Widget build(BuildContext context) {
print(selectedZoneList);
return Scaffold(
backgroundColor: Colors.grey[800],
appBar: getAppBar(),
body: Padding(
padding: const EdgeInsets.fromLTRB(15, 5, 15, 5),
child: GridView.builder(
itemCount: itemZoneList.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1.72,
crossAxisSpacing: 10,
mainAxisSpacing: 20),
itemBuilder: (context, index) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
// color: _calculateColor(index),
elevation: 10.0,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
GridItemMap(
map: itemZoneList[index],
isSelected: (bool value) {
setState(() {
if (value) {
selectedZoneList.add(itemZoneList[index]);
print("$index : $value");
} else {
selectedZoneList.remove(itemZoneList[index]);
}
});
},
key: Key(itemZoneList[index].rank.toString())),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 4),
child: Text('$zoneName',
style: TextStyle(color: Colors.white),),
),
]));
}),
),
);
}
// Color _calculateColor(int index) {
// if (index <= 18) {
// return Colors.orange[800];
// } else if (index >= 19 && index <= 63) {
// return Colors.amber[600];
// } else if (index >= 64 && index <= 96) {
// return Colors.purple[100];
// } else if (index >= 97 && index <= 113) {
// return Colors.lightBlueAccent[400];
// } else if (index >= 114 && index <= 118) {
// return Colors.limeAccent;
// }
// //etc
//default case, shouldn't reach here
// return Colors.grey;
// }
getAppBar() {
return AppBar(
backgroundColor: Colors.grey[850],
elevation: 0.0,
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.chevron_left),
onPressed: () => Navigator.pushReplacementNamed(context, '/home')),
title: Text("Map Selection"));
}
}
class Zone {
String imageUrl;
int rank;
Zone(this.imageUrl, this.rank);
}
解决方案
推荐阅读
- regex - 正则表达式:如何检测特定文本,后跟特定数字?
- excel - VBA excel - 使用 powershell 脚本创建 Skype 帐户
- php - 如何使用 Illuminate\Http\Request 添加请求数据以支持电子邮件;
- amazon-web-services - 从 Ansible 获取正确的子网 ID
- c# - transform.localposition 有很大的延迟
- dart - 如何在小部件的子级中使用“for”循环?
- python - 如何检查点是否位于轮廓内?
- java - java - 如果操作系统被挂起,正在休眠的线程会发生什么?
- php - 如何使用 symfony 3.4 在服务中获取当前登录的用户
- specman - Specman e:有没有办法打印单元实例名称?