cupertino_will_pop_scope
Cupertino 페이지 전환에서 'onWillPop' 콜백을 활성화하고 거부된 '스와이프하여 뒤로 가기' 제스처의 시각적 피드백을 향상시킵니다.
Flutter의 CupertinoPageRoute의 향상된 버전
{"sdk":"flutter"}{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Note: This package can be used on any platform, and is not specific to iOS.
ConditionalWillPopScopeandCupertinoWillPopScopePageTransionsBuildercan each be used seprately.
The key to this package is a modified version of Flutter's CupertinoPageRoute, which has been enhanced with the following:
willPop callbacks, they are triggered once the screen is snapped back to place.When using this widget, be sure to update shouldAddCallbacks based on the state of your screen, and only set it to true when the screen should not be allowed to pop. Additionally, the onWillPop property should not be changed once set.
A working app using this package can be found in the example folder.
To use this package, add cupertino_will_pop_scope as a dependency in your pubspec.yaml file.
// main.dart
import 'package:decorated_icon/cupertino_will_pop_scope.dart';
Set the transition builder of the desired platform to CupertinoWillPopScopePageTransionsBuilder in your theme configuration.
// main.dart
theme = ThemeData(
...
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoWillPopScopePageTransionsBuilder(),
},
),
);
Make sure the theme is applied to the app.
// main.dart
MaterialApp(
...
theme: theme,
home: HomeScreen(),
);
Using the included ConditionalWillPopScope widget, or Flutter's WillPopScope widget, wrap your screen and define an onWillPop callback for it.
Note that
onWillPopshould always return abool. See the Flutter Docs for more.
// my_screen.dart
@override
Widget build(BuildContext context) {
return ConditionalWillPopScope(
child: _MyScreenContent(),
onWillPop: _onWillPop,
shouldAddCallbacks: _hasChanges,
);
}
// my_screen.dart
@override
Widget build(BuildContext context) {
return WillPopScope(
child: _MyScreenContent(),
onWillPop: _hasChanges ? _onWillPop : null,
);
}
:warning: When using Flutter's
WillPopScopewidget, theonWillPopmust be set conditionally. Otherwise, the "swipe to go back" gesture will be cancelled. In the example above, this is achieved by using_hasChangesas the condition.