Home > front end >  Is there a way to avoid using 'null' to show appbar actions with condition in Flutter?
Is there a way to avoid using 'null' to show appbar actions with condition in Flutter?

Time:12-27

I wonder if there is a way to avoid setting null to actions if i have this state condition:

appBar: AppBar(
      title: provider.appBarTitle,
      actions: provider.editState == EditState.inactive
          ? [
              IconButton(
                  onPressed: provider.activateEditableState,
                  icon: const Icon(Icons.edit))
            ]
          : null)

CodePudding user response:

It should be fine if you return an empty list instead of null.

appBar: AppBar(
  title: provider.appBarTitle,
  actions: [
    if (provider.editState == EditState.inactive)
      IconButton(
        onPressed: provider.activateEditableState,
        icon: const Icon(Icons.edit),
      ),
  ],
),
  • Related