circle_app/circle_app/lib/app/select_circle/view.dart
2023-06-27 17:20:59 +08:00

153 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../components/my_app_bar.dart';
import '../../util/util.dart';
import 'logic.dart';
class Select_circlePage extends StatelessWidget {
Select_circlePage({Key? key}) : super(key: key);
final logic = Get.find<Select_circleLogic>();
final state = Get.find<Select_circleLogic>().state;
@override
Widget build(BuildContext context) {
return GetBuilder(builder: (Select_circleLogic controller) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(getBaseImage("home_back")),
fit: BoxFit.cover,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: MyAppBar(
centerTitle: '选择感兴趣的圈子',
actionWdiget: Text(
"提交",
style: TextStyle(color: Colors.white),
),
onPressed: () {
// showToast("提交");
List<MyConfigData> numbers = [];
controller.arrList.forEach((element) {
if (element.isSelect) {
numbers.add(element);
}
});
if (numbers.length > 0) {
Navigator.pop(context, numbers);
} else {
showToast("请选择兴趣圈子");
}
},
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
margin: EdgeInsets.only(top: 20.sp),
child: _reportAdapter(controller),
),
),
],
),
),
);
});
}
var selectIndex = -1;
Widget _reportAdapter(Select_circleLogic controller) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
// crossAxisSpacing: 6.sp,
mainAxisSpacing: 10.sp,
childAspectRatio: 3,
),
itemCount: controller.getItemList().length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
if (controller.isRodio) {
if(selectIndex != -1){
controller.arrList[selectIndex].isSelect = false;
print(selectIndex);
}
selectIndex = index;
controller.arrList[index].isSelect = true;
controller.update();
} else {
controller.arrList[index].isSelect = !controller.arrList[index].isSelect;
controller.update();
}
},
child: _getItemSelect(controller.arrList[index]),
);
},
);
}
Widget _getItemSelect(MyConfigData bean) {
if (bean.isSelect) {
return Container(
margin:
EdgeInsets.only(left: 8.sp, right: 8.sp, top: 6.sp, bottom: 6.sp),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.sp),
gradient: LinearGradient(
colors: [
Color(0xFF06F9FA),
Color(0xFFDC5BFD),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
child: Center(
child: Text(
bean.name,
style: TextStyle(
color: Colors.white,
fontSize: 11.sp,
),
),
),
);
} else {
return Container(
margin:
EdgeInsets.only(left: 8.sp, right: 8.sp, top: 6.sp, bottom: 6.sp),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0), // 设置圆角半径
border: Border.all(
color: Color(0xFF392D53),
),
color: Color(0xFF392D53),
),
child: Padding(
padding: EdgeInsets.only(
top: 0.sp, bottom: 0.sp, left: 15.sp, right: 15.sp),
child: Center(
child: Text(
bean.name,
style: TextStyle(
fontSize: 11.0,
color: Colors.white,
),
),
),
),
),
);
}
}
}