Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️Migrate to Flutter3.13 #38

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
4 changes: 1 addition & 3 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a MIT license that can be found in the
// LICENSE file.

import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:oktoast/oktoast.dart';
Expand Down Expand Up @@ -43,7 +41,7 @@ class JJAppState extends State<JJApp> with WidgetsBindingObserver {
return OKToast(
duration: const Duration(seconds: 3),
position: ToastPosition.bottom.copyWith(
offset: -MediaQueryData.fromWindow(ui.window).size.height / 12,
offset: -Screens.mediaQuery.size.height / 12,
),
radius: 5,
child: child,
Expand Down
9 changes: 7 additions & 2 deletions lib/constants/screens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// Use of this source code is governed by a MIT license that can be found in the
// LICENSE file.

import 'dart:ui' as ui;
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class Screens {
const Screens._();

static MediaQueryData get mediaQuery => MediaQueryData.fromWindow(ui.window);
static MediaQueryData get mediaQuery => MediaQueryData.fromView(
WidgetsBinding.instance.platformDispatcher.views.first,
);

static double fixedFontSize(double fontSize) => fontSize / textScaleFactor;

Expand All @@ -37,6 +39,9 @@ class Screens {

static double get safeHeight => height - topSafeHeight - bottomSafeHeight;

static FlutterView get window =>
WidgetsBinding.instance.platformDispatcher.views.first;

static void updateStatusBarStyle(SystemUiOverlayStyle style) {
SystemChrome.setSystemUIOverlayStyle(style);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/exports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ export 'package:diox/diox.dart';
export 'package:ff_annotation_route_library/ff_annotation_route_library.dart';
export 'package:flutter/services.dart' show HapticFeedback, TextInputFormatter;
export 'package:flutter_svg/flutter_svg.dart' show SvgPicture;
export 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart'
hide CupertinoActivityIndicator;
export 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart';

export 'apis/content_api.dart';
export 'apis/interact_api.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/models/data_model.d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ part of 'data_model.dart';

final Map<Type, DataFactory> dataModelFactories = <Type, DataFactory>{
EmptyDataModel: EmptyDataModel.fromJson,
FeedModel: FeedModel.fromJson,
AdvertiseItemModel: AdvertiseItemModel.fromJson,
ArticleItemModel: ArticleItemModel.fromJson,
ArticleInfo: ArticleInfo.fromJson,
Expand All @@ -18,7 +19,6 @@ final Map<Type, DataFactory> dataModelFactories = <Type, DataFactory>{
PinTopic: PinTopic.fromJson,
PinTheme: PinTheme.fromJson,
HotComment: HotComment.fromJson,
FeedModel: FeedModel.fromJson,
UserInfoModel: UserInfoModel.fromJson,
UserUniversity: UserUniversity.fromJson,
UserMajor: UserMajor.fromJson,
Expand Down
46 changes: 25 additions & 21 deletions lib/models/data_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/models/item/advertise_item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AdvertiseItemModel extends DataModel {
final int advertType;
final int stationType;
final String authorName;
final int authorId;
final String authorId;
final String title;
final String brief;
final String url;
Expand Down
20 changes: 10 additions & 10 deletions lib/models/item/article_item_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ArticleItemModel extends DataModel {
required this.reqId,
required this.status,
this.authorInteract,
required this.extra,
this.extra,
});

factory ArticleItemModel.fromJson(Map<String, dynamic> json) =>
Expand All @@ -34,7 +34,7 @@ class ArticleItemModel extends DataModel {
final String reqId;
final ArticleStatus status;
final Object? authorInteract;
final ArticleExtra extra;
final ArticleExtra? extra;

@override
Map<String, dynamic> toJson() => _$ArticleItemModelToJson(this);
Expand Down Expand Up @@ -205,19 +205,19 @@ class ArticleStatus extends DataModel {
@JsonSerializable()
class ArticleExtra extends DataModel {
const ArticleExtra({
required this.boostType,
this.boostType,
});

factory ArticleExtra.fromJson(Map<String, dynamic> json) =>
_$ArticleExtraFromJson(json);

final String boostType;
final String? boostType;

@override
Map<String, dynamic> toJson() => _$ArticleExtraToJson(this);

@override
List<Object?> get props => <Object>[boostType];
List<Object?> get props => <Object?>[boostType];
}

@JsonSerializable()
Expand All @@ -229,12 +229,12 @@ class Category extends DataModel {
required this.rank,
required this.backGround,
required this.icon,
required this.ctime,
required this.mtime,
required this.showType,
required this.itemType,
required this.promoteTagCap,
required this.promotePriority,
this.ctime,
this.mtime,
});

factory Category.fromJson(Map<String, dynamic> json) =>
Expand All @@ -246,8 +246,8 @@ class Category extends DataModel {
final int rank;
final String backGround;
final String icon;
final int ctime;
final int mtime;
final int? ctime;
final int? mtime;
final int showType;
final int itemType;
final int promoteTagCap;
Expand All @@ -257,7 +257,7 @@ class Category extends DataModel {
Map<String, dynamic> toJson() => _$CategoryToJson(this);

@override
List<Object?> get props => <Object>[
List<Object?> get props => <Object?>[
categoryId,
categoryName,
categoryUrl,
Expand Down
11 changes: 7 additions & 4 deletions lib/models/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class UserInfoModel extends DataModel {
@JsonKey(name: 'extramap')
final Object? extraMap;
final int isLogout;
final List<Object> annualInfo;
final List<Object>? annualInfo;
final int accountAmount;
final UserGrowthInfo userGrowthInfo;
final UserGrowthInfo? userGrowthInfo;
final bool isVip;

Widget buildCircleAvatar({double? size}) {
Expand All @@ -100,9 +100,12 @@ class UserInfoModel extends DataModel {
}

Widget buildVipImage({double? size}) {
if (userGrowthInfo == null) {
return const SizedBox();
}
final String asset = R.ASSETS_ICON_USER_VIP_LV1_WEBP.replaceAll(
'1',
'${userGrowthInfo.vipLevel}',
'${userGrowthInfo!.vipLevel}',
);
return Image.asset(asset, width: size, height: size, fit: BoxFit.cover);
}
Expand All @@ -114,7 +117,7 @@ class UserInfoModel extends DataModel {
Text(userName),
const SizedBox(width: 4),
if (level > 0) buildLevelImage(width: levelWidth, height: levelHeight),
if (userGrowthInfo.vipLevel > 0)
if (userGrowthInfo != null && userGrowthInfo!.vipLevel > 0)
Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: buildVipImage(size: levelHeight * 1.375),
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/article/detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';
import 'dart:io';
import 'dart:ui' as ui;

import 'package:extended_sliver/extended_sliver.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -281,7 +280,7 @@ class _ArticleDetailPageState extends State<ArticleDetailPage> {
double y = scrollOffset;
if (Platform.isAndroid) {
// https://github.com/flutter/flutter/issues/75841
y *= ui.window.devicePixelRatio;
y *= Screens.window.devicePixelRatio;
}
_controller!.controller?.scrollTo(x: 0, y: y.ceil());
},
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/club/club.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ class _PinItemWidget extends StatelessWidget {
color: context.textTheme.headlineSmall?.color,
),
),
if (user.userGrowthInfo.vipLevel > 0)
if (user.userGrowthInfo != null &&
user.userGrowthInfo!.vipLevel > 0)
Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: user.buildVipImage(size: 16),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/home/mine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _MinePageState extends State<MinePage> {
children: [
counter(0, context.l10n.userLikes),
counter(0, context.l10n.userFavorites),
counter(0, context.l10n.userFollows)
counter(0, context.l10n.userFollows),
],
),
);
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home/pins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class _PinItemWidget extends StatelessWidget {
color: context.textTheme.headlineSmall?.color,
),
),
if (user.userGrowthInfo.vipLevel > 0)
if (user.userGrowthInfo != null &&
user.userGrowthInfo!.vipLevel > 0)
Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: user.buildVipImage(size: 16),
Expand Down
Loading