From 302cc3938e938513c44543e0e75a966e44185937 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Tue, 21 May 2024 23:39:24 +0800 Subject: [PATCH] Migrate deprecated code in flutter 3.16 --- .../android/content_uri_image_provider.dart | 6 +- app/lib/widget/dialog_scaffold.dart | 4 +- app/lib/widget/processing_dialog.dart | 4 +- app/lib/widget/settings/account_settings.dart | 131 +++++++++--------- app/lib/widget/splash.dart | 4 +- np_ui/lib/src/pixel_image_provider.dart | 3 +- 6 files changed, 76 insertions(+), 76 deletions(-) diff --git a/app/lib/mobile/android/content_uri_image_provider.dart b/app/lib/mobile/android/content_uri_image_provider.dart index ce440791..7d99bd36 100644 --- a/app/lib/mobile/android/content_uri_image_provider.dart +++ b/app/lib/mobile/android/content_uri_image_provider.dart @@ -23,8 +23,8 @@ class ContentUriImage extends ImageProvider } @override - ImageStreamCompleter loadBuffer( - ContentUriImage key, DecoderBufferCallback decode) { + ImageStreamCompleter loadImage( + ContentUriImage key, ImageDecoderCallback decode) { return MultiFrameImageStreamCompleter( codec: _loadAsync(key, decode), scale: key.scale, @@ -36,7 +36,7 @@ class ContentUriImage extends ImageProvider } Future _loadAsync( - ContentUriImage key, DecoderBufferCallback decode) async { + ContentUriImage key, ImageDecoderCallback decode) async { assert(key == this); final bytes = await ContentUri.readUri(uri); if (bytes.lengthInBytes == 0) { diff --git a/app/lib/widget/dialog_scaffold.dart b/app/lib/widget/dialog_scaffold.dart index 74e4ceb0..2c4a0b2c 100644 --- a/app/lib/widget/dialog_scaffold.dart +++ b/app/lib/widget/dialog_scaffold.dart @@ -18,8 +18,8 @@ class DialogScaffold extends StatelessWidget { Navigator.of(context).pop(); } }, - child: WillPopScope( - onWillPop: () => Future.value(canPop), + child: PopScope( + canPop: canPop, child: Scaffold( backgroundColor: Colors.transparent, body: GestureDetector( diff --git a/app/lib/widget/processing_dialog.dart b/app/lib/widget/processing_dialog.dart index aa68ce29..162b2e57 100644 --- a/app/lib/widget/processing_dialog.dart +++ b/app/lib/widget/processing_dialog.dart @@ -8,8 +8,8 @@ class ProcessingDialog extends StatelessWidget { @override build(BuildContext context) { - return WillPopScope( - onWillPop: () => Future.value(false), + return PopScope( + canPop: false, child: AlertDialog( content: Row( mainAxisSize: MainAxisSize.min, diff --git a/app/lib/widget/settings/account_settings.dart b/app/lib/widget/settings/account_settings.dart index f9b5b385..a18cdbcd 100644 --- a/app/lib/widget/settings/account_settings.dart +++ b/app/lib/widget/settings/account_settings.dart @@ -146,80 +146,81 @@ class _WrappedAccountSettingsState extends State<_WrappedAccountSettings> }, ), ], - child: WillPopScope( - onWillPop: () async => !_bloc.state.shouldReload, - child: CustomScrollView( - slivers: [ - SliverAppBar( - pinned: true, - title: Text(L10n.global().settingsAccountTitle), - leading: _BlocSelector( - selector: (state) => state.shouldReload, - builder: (_, state) => - state ? const _DoneButton() : const BackButton(), + child: _BlocSelector( + selector: (state) => state.shouldReload, + builder: (_, shouldReload) => PopScope( + canPop: !shouldReload, + child: CustomScrollView( + slivers: [ + SliverAppBar( + pinned: true, + title: Text(L10n.global().settingsAccountTitle), + leading: + shouldReload ? const _DoneButton() : const BackButton(), ), - ), - SliverList( - delegate: SliverChildListDelegate( - [ - _BlocSelector( - selector: (state) => state.label, - builder: (context, state) => ListTile( - title: Text(L10n.global().settingsAccountLabelTitle), - subtitle: Text(state ?? - L10n.global().settingsAccountLabelDescription), - onTap: () => _onLabelPressed(context), + SliverList( + delegate: SliverChildListDelegate( + [ + _BlocSelector( + selector: (state) => state.label, + builder: (context, state) => ListTile( + title: Text(L10n.global().settingsAccountLabelTitle), + subtitle: Text(state ?? + L10n.global().settingsAccountLabelDescription), + onTap: () => _onLabelPressed(context), + ), ), - ), - _BlocSelector( - selector: (state) => state.account, - builder: (context, state) => ListTile( - title: Text(L10n.global().settingsIncludedFoldersTitle), - subtitle: - Text(state.roots.map((e) => "/$e").join("; ")), - onTap: () => _onIncludedFoldersPressed(context), + _BlocSelector( + selector: (state) => state.account, + builder: (context, state) => ListTile( + title: + Text(L10n.global().settingsIncludedFoldersTitle), + subtitle: + Text(state.roots.map((e) => "/$e").join("; ")), + onTap: () => _onIncludedFoldersPressed(context), + ), ), - ), - _BlocSelector( - selector: (state) => state.shareFolder, - builder: (context, state) => ListTile( - title: Text(L10n.global().settingsShareFolderTitle), - subtitle: Text("/$state"), - onTap: () => _onShareFolderPressed(context), + _BlocSelector( + selector: (state) => state.shareFolder, + builder: (context, state) => ListTile( + title: Text(L10n.global().settingsShareFolderTitle), + subtitle: Text("/$state"), + onTap: () => _onShareFolderPressed(context), + ), ), - ), - SettingsListCaption( - label: L10n.global().settingsServerAppSectionTitle, - ), - _BlocSelector( - selector: (state) => state.personProvider, - builder: (context, state) { - if (_bloc.highlight == - AccountSettingsOption.personProvider) { - return AnimatedBuilder( - animation: _highlightAnimation, - builder: (context, child) => ListTile( + SettingsListCaption( + label: L10n.global().settingsServerAppSectionTitle, + ), + _BlocSelector( + selector: (state) => state.personProvider, + builder: (context, state) { + if (_bloc.highlight == + AccountSettingsOption.personProvider) { + return AnimatedBuilder( + animation: _highlightAnimation, + builder: (context, child) => ListTile( + title: Text( + L10n.global().settingsPersonProviderTitle), + subtitle: Text(state.toUserString()), + onTap: () => _onPersonProviderPressed(context), + tileColor: _highlightAnimation.value, + ), + ); + } else { + return ListTile( title: Text( L10n.global().settingsPersonProviderTitle), subtitle: Text(state.toUserString()), onTap: () => _onPersonProviderPressed(context), - tileColor: _highlightAnimation.value, - ), - ); - } else { - return ListTile( - title: - Text(L10n.global().settingsPersonProviderTitle), - subtitle: Text(state.toUserString()), - onTap: () => _onPersonProviderPressed(context), - ); - } - }, - ), - ], + ); + } + }, + ), + ], + ), ), - ), - ], + ], + ), ), ), ), diff --git a/app/lib/widget/splash.dart b/app/lib/widget/splash.dart index 6f53d9dd..b2bd92b8 100644 --- a/app/lib/widget/splash.dart +++ b/app/lib/widget/splash.dart @@ -70,8 +70,8 @@ class _SplashState extends State { @override build(BuildContext context) { return Scaffold( - body: WillPopScope( - onWillPop: () => Future.value(false), + body: PopScope( + canPop: false, child: Builder(builder: (context) => _buildContent(context)), ), ); diff --git a/np_ui/lib/src/pixel_image_provider.dart b/np_ui/lib/src/pixel_image_provider.dart index f09c8fa9..8ed60c13 100644 --- a/np_ui/lib/src/pixel_image_provider.dart +++ b/np_ui/lib/src/pixel_image_provider.dart @@ -17,8 +17,7 @@ class PixelImage extends ImageProvider { SynchronousFuture(this); @override - ImageStreamCompleter loadBuffer( - PixelImage key, DecoderBufferCallback decode) => + ImageStreamCompleter loadImage(PixelImage key, ImageDecoderCallback decode) => OneFrameImageStreamCompleter(_createImageInfo()); Future _createImageInfo() async {