Skip to content

Commit

Permalink
feat: 升级至 Flutter 3.24 (#430)
Browse files Browse the repository at this point in the history
* chore: 更新 flutter 版本

* refactor: 删除多余的 library 名称

* refactor: 使用 onPopInvokedWithResult

<https://docs.flutter.dev/release/breaking-changes/popscope-with-result>

* refactor: 使用 onDidRemovePage

<https://docs.flutter.dev/release/breaking-changes/navigator-and-page-api>

* chore: 跳过检查
  • Loading branch information
he0119 authored Dec 4, 2024
1 parent f213323 commit 2f64c38
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/blog/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _BlogHomeScreenState extends State<BlogHomeScreen> {
),
// FIXME: 目前没法通过返回键退出应用
canPop: () => false,
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, result) async {
if (didPop) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/board/model/board.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library board;
library;

import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/core/model/push.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library push;
library;

import 'package:json_annotation/json_annotation.dart';

import 'package:smarthome/user/user.dart';

part 'push.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/view/admin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _AdminScreenState extends State<AdminScreen> {
return Scaffold(
body: PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {
onPopInvokedWithResult: (bool didPop, Object? result) async {
if (didPop) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/iot/model/iot.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library iot;
library;

import 'package:json_annotation/json_annotation.dart';

Expand Down
13 changes: 4 additions & 9 deletions lib/routers/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,9 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
notifyListeners();
}

bool _handlePopPage(Route<dynamic> route, dynamic result) {
final success = route.didPop(result);
if (success) {
_log.fine('Pop ${route.settings.name}');
_pages.remove(route.settings);
notifyListeners();
}
return success;
void _handleRemovePage(Page<Object?> page) {
_pages.remove(page);
notifyListeners();
}

// 网页版显示网址
Expand Down Expand Up @@ -313,7 +308,7 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
child: Navigator(
key: navigatorKey,
pages: pages,
onPopPage: _handlePopPage,
onDidRemovePage: _handleRemovePage,
// transitionDelegate: transitionDelegate,
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/storage/model/storage.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library storage;
library;

import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/storage/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class StorageHomeScreen extends StatelessWidget {
return state is StorageHomeSuccess &&
state.itemType == ItemType.all;
},
onPopInvoked: (didPop) {
onPopInvokedWithResult: (didPop, result) {
if (state is StorageHomeSuccess) {
BlocProvider.of<StorageHomeBloc>(context)
.add(const StorageHomeFetched(itemType: ItemType.all));
Expand Down
2 changes: 2 additions & 0 deletions lib/storage/view/widgets/scan_qr_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class _ScanQRPageState extends State<ScanQRPage> {
setState(() {
jumped = true;
});
// TODO: 弄清楚这里是什么情况,没看懂哪里来的 async gap。
// ignore: use_build_context_synchronously
MyRouterDelegate.of(context)
.push(StorageDetailPage(storageId: storageId));
// 只有安卓设备支持暂停相机
Expand Down
3 changes: 3 additions & 0 deletions lib/storage/view/widgets/storage_picker_formfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class _StorageFieldState extends FormFieldState<Storage> {
}

void _hideKeyboard() {
// ignore: use_build_context_synchronously
Future.microtask(() => FocusScope.of(context).requestFocus(FocusNode()));
}

Expand All @@ -242,6 +243,8 @@ class _StorageFieldState extends FormFieldState<Storage> {
.storages(key: '', cache: false);
if (context.mounted) {
final newValue = await showDialog<Storage>(
// TODO: 这里也不清楚,明明已经检查过 mounted 了。
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return StorageDialog(
Expand Down
2 changes: 1 addition & 1 deletion lib/user/model/user.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library user;
library;

import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down
12 changes: 6 additions & 6 deletions lib/widgets/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyHomePage extends StatelessWidget {
final Widget? floatingActionButton;
final Future<void> Function()? onRefresh;
final bool Function()? canPop;
final void Function(bool)? onPopInvoked;
final void Function(bool, Object?)? onPopInvokedWithResult;

const MyHomePage({
super.key,
Expand All @@ -22,7 +22,7 @@ class MyHomePage extends StatelessWidget {
this.floatingActionButton,
this.onRefresh,
this.canPop,
this.onPopInvoked,
this.onPopInvokedWithResult,
});

@override
Expand All @@ -40,7 +40,7 @@ class MyHomePage extends StatelessWidget {
BlocProvider.of<TabBloc>(context).add(TabChanged(tab)),
),
canPop: canPop,
onPopInvoked: onPopInvoked,
onPopInvokedWithResult: onPopInvokedWithResult,
);
}
}
Expand All @@ -60,7 +60,7 @@ class MySliverScaffold extends StatelessWidget {
final Future<void> Function()? onRefresh;
final AppBarSize appBarSize;
final bool Function()? canPop;
final void Function(bool)? onPopInvoked;
final void Function(bool, Object?)? onPopInvokedWithResult;

const MySliverScaffold({
super.key,
Expand All @@ -75,7 +75,7 @@ class MySliverScaffold extends StatelessWidget {
this.appbarBottom,
this.appBarSize = AppBarSize.medium,
this.canPop,
this.onPopInvoked,
this.onPopInvokedWithResult,
});

@override
Expand All @@ -84,7 +84,7 @@ class MySliverScaffold extends StatelessWidget {
drawer: drawer,
body: PopScope(
canPop: canPop == null ? true : canPop!(),
onPopInvoked: onPopInvoked,
onPopInvokedWithResult: onPopInvokedWithResult,
child: ConditionalParentWidget(
condition: onRefresh != null,
conditionalBuilder: (child) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1650,4 +1650,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.24.2"
flutter: ">=3.24.5"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: "none"

environment:
sdk: ">=3.4.0 <4.0.0"
flutter: "3.24.2" # This must be exact! No ranges allowed.
flutter: "3.24.5" # This must be exact! No ranges allowed.

dependencies:
flutter:
Expand Down

0 comments on commit 2f64c38

Please sign in to comment.