Hayden Young
Hayden Young

Reputation: 356

Why does Flutter's WillPopScope always block going back?

Whenever I've tried to block the ability to swipe back with Flutter on iOS I've tried using WillPopScope. However, regardless of what value I put in onWillPop: it will always block the ability to swipe back.

Why is this? It doesn't matter if onWillPop returns true or false, it always blocks.

    final isConfirmation = _isConfirmation();
    WillPopScope(
      child: Scaffold(
        appBar: _appBar(),
        body: _body(),
      ),
      onWillPop: () async => isConfirmation,
    );

This issue happens even if I return a hard true or false

onWillPop: () async => true

onWillPop: () async => false

onWillPop: () => Future<bool>.value(true)

onWillPop: () => Future<bool>.value(false)

Upvotes: 0

Views: 1020

Answers (1)

Hadi
Hadi

Reputation: 652

Change your code to this.

if _isConfirmation() is a Future method, use await before it in the code below.

onWillPop: () async {
  final bool confirmation = _isConfirmation();  // use await if it is future.
  return Future<bool>.value(confirmation);
}

Upvotes: 0

Related Questions