117 lines
3.7 KiB
Dart
117 lines
3.7 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../beans/memory_card_bean.dart';
|
|
|
|
class MemoryCardDialog extends StatefulWidget {
|
|
Function onTap;
|
|
|
|
List<MemoryCardBean> memoryCardList;
|
|
|
|
MemoryCardDialog({required this.onTap, required this.memoryCardList});
|
|
|
|
@override
|
|
State<MemoryCardDialog> createState() => _MemoryCardDialogState();
|
|
}
|
|
|
|
class _MemoryCardDialogState extends State<MemoryCardDialog> {
|
|
int currentIndex = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Material(
|
|
type: MaterialType.transparency, //透明类型
|
|
color: Color(0x1A000000),
|
|
child: Container(
|
|
decoration:
|
|
BoxDecoration(color: Color(0xFF19191A), borderRadius: BorderRadius.only(topLeft: Radius.circular(7), topRight: Radius.circular(7))),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
width: 24.7,
|
|
height: 3,
|
|
margin: EdgeInsets.only(top: 12),
|
|
decoration: BoxDecoration(color: Color(0xFF272734), borderRadius: BorderRadius.all(Radius.circular(7))),
|
|
),
|
|
Container(
|
|
height: 300,
|
|
margin: EdgeInsets.only(top: 38, left: 19, bottom: 10, right: 19),
|
|
child: GridView.count(
|
|
shrinkWrap: true,
|
|
//水平子Widget之间间距
|
|
crossAxisSpacing: 12.0,
|
|
//垂直子Widget之间间距
|
|
mainAxisSpacing: 14.0,
|
|
//GridView内边距
|
|
padding: EdgeInsets.zero,
|
|
//一行的Widget数量
|
|
crossAxisCount: 2,
|
|
//子Widget宽高比例
|
|
childAspectRatio: 1.54,
|
|
//子Widget列表
|
|
children: _item(),
|
|
//类似 cellForRow 函数
|
|
scrollDirection: Axis.vertical),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
widget.onTap(widget.memoryCardList[currentIndex].propId);
|
|
},
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 40,
|
|
margin: EdgeInsets.all(18),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFFFF9000),
|
|
borderRadius: BorderRadius.all(Radius.circular(7)),
|
|
),
|
|
child: Text(
|
|
'使用记忆提升卡',
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_item() {
|
|
return widget.memoryCardList.map((res) {
|
|
int index = widget.memoryCardList.indexOf(res);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
currentIndex = index;
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF2A2A2A),
|
|
border: Border.all(color: currentIndex == index ? Color(0xFFFF9000) : Color(0xFF2A2A2A), width: 1),
|
|
borderRadius: BorderRadius.all(Radius.circular(7))),
|
|
child: CachedNetworkImage(
|
|
fit: BoxFit.cover,
|
|
imageUrl: res.imgUrl!,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}).toList();
|
|
}
|
|
}
|