英文:
i am building app from Udemy . when I press drawing button it stuck and throw function error
问题
抱歉,我无法完成你的要求。
英文:
I am building filter page in drawing when I press on filter page it throw error message. it is because of function which I have used .
////////////////////////////
/////////////////////////////////////
////////////////////////////////////
/////////////////////////////////
//////////////////////////////
import 'package:f2/widgets/main_drawer.dart';
import 'package:flutter/material.dart';
class FilterScreen extends StatefulWidget {
static const routeName = '/filters';
@override
State<FilterScreen> createState() => _FilterScreenState();
}
class _FilterScreenState extends State<FilterScreen> {
bool _glutenFree = false;
bool _vegetarian = false;
bool _vegan = false;
bool _lactoseFree = false;
Widget _buildSwitchListTitle(
String title, String description, bool currentValue, Function function) {
return SwitchListTile(
title: Text(title),
value: currentValue,
subtitle: Text(description),
onChanged: function(),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(" filter page"),
),
drawer: MainDrawer(),
body: Column(
children: [
Container(
padding: EdgeInsets.all(20),
child: Text(
"Adjust your meal selection",
style: Theme.of(context).textTheme.titleMedium,
),
),
Expanded(
child: ListView(
children: [
_buildSwitchListTitle(
"Gluten - free",
"Only include Gluten-free meals",
_glutenFree,
(value) => setState(() {
_glutenFree = value;
}),
)
],
))
],
),
);
}
}
答案1
得分: 0
尝试以下代码:
```dart
Widget _buildSwitchListTitle(
String title,
String description,
bool currentValue,
void Function(bool) function,
) {
return SwitchListTile(
title: Text(title),
value: currentValue,
subtitle: Text(description),
onChanged: function,
);
}
<details>
<summary>英文:</summary>
Try the following code:
```dart
Widget _buildSwitchListTitle(
String title,
String description,
bool currentValue,
void Function(bool) function,
) {
return SwitchListTile(
title: Text(title),
value: currentValue,
subtitle: Text(description),
onChanged: function,
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论