i am building app from Udemy . when I press drawing button it stuck and throw function error

huangapple go评论52阅读模式
英文:

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 .

////////////////////////////

/////////////////////////////////////

i am building app from Udemy . when I press drawing button it stuck and throw function error

////////////////////////////////////
i am building app from Udemy . when I press drawing button it stuck and throw function error

/////////////////////////////////

i am building app from Udemy . when I press drawing button it stuck and throw function error
////////////////

//////////////////////////////

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,
  );
}

huangapple
  • 本文由 发表于 2023年2月19日 14:40:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75498432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定