我正在尝试添加CheckboxListTile
onSlidingUpPanel
但它显示错误为“ The element type 'List<CheckboxListTile>' can't be assigned to the list type 'Widget'.
”
我该如何解决这个问题并使代码可用?
这是我的代码:
import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
final Color color = Color(0xff181725);
class Filters extends StatefulWidget {
@override
State<Filters> createState() => _FiltersState();
}
class _FiltersState extends State<Filters> {
bool isChecked = false;
Map<String, bool> categories = <String, bool>{
"Eggs": false,
"Noodles & Pasta": false,
"Chips & Crisps": false,
"Fast Food": false,
};
Map<String, bool> brand = <String, bool>{
"Individual Callection": false,
"Cocola": false,
"Ifad": false,
"Kazi Farmas": false,
};
@override
Widget build(BuildContext context) {
BorderRadiusGeometry radius = BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
);
return Scaffold(
appBar: AppBar(
leading: Icon(
Icons.close_rounded,
color: color,
),
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
title: Text(
"Filters",
style: TextStyle(
color: color,
fontFamily: "Gilroy",
fontWeight: FontWeight.bold,
fontSize: 20,
wordSpacing: 1,
),
),
),
body: SlidingUpPanel(
boxShadow: const [
BoxShadow(
blurRadius: 0,
color: Colors.transparent,
),
],
borderRadius: radius,
panel: Padding(
padding: const EdgeInsets.only(left: 10),
child: Column(
children: [
Text(
'''Categories''',
style: TextStyle(
color: color,
fontSize: 24,
fontFamily: "Gilroy",
fontWeight: FontWeight.normal,
),
),
ListView(
children: [
categories.keys.map((String key) {
return CheckboxListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
controlAffinity: ListTileControlAffinity.leading,
activeColor: Color(0xff53B175),
checkColor: Color(0xffFFFFFF),
value: categories[key],
onChanged: (bool? value) {
setState(() {
categories[key] = value!;
});
},
title: Text(
"{$key}",
style: TextStyle(
fontSize: 16,
fontFamily: "Gilroy",
fontWeight: FontWeight.normal,
),
),
);
}).toList(),
],
),
],
),
),
collapsed: Container(
decoration: BoxDecoration(
color: Color(0xffF2F3F2),
borderRadius: radius,
),
),
),
);
}
}