Skip to content

Commit

Permalink
update support 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed May 16, 2023
1 parent d228ff7 commit 40faf94
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 215 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply from: "exported.gradle"

android {
compileSdkVersion 32
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
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
}
33 changes: 14 additions & 19 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gsy_github_app_flutter/common/event/http_error_event.dart';
import 'package:gsy_github_app_flutter/common/event/index.dart';
import 'package:gsy_github_app_flutter/common/localization/default_localizations.dart';
import 'package:gsy_github_app_flutter/common/localization/gsy_localizations_delegate.dart';
import 'package:gsy_github_app_flutter/page/debug/debug_label.dart';
import 'package:gsy_github_app_flutter/page/photoview_page.dart';
import 'package:gsy_github_app_flutter/redux/gsy_state.dart';
import 'package:gsy_github_app_flutter/model/User.dart';
import 'package:gsy_github_app_flutter/common/net/code.dart';
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
import 'package:gsy_github_app_flutter/common/utils/common_utils.dart';
import 'package:gsy_github_app_flutter/model/User.dart';
import 'package:gsy_github_app_flutter/page/debug/debug_label.dart';
import 'package:gsy_github_app_flutter/page/home/home_page.dart';
import 'package:gsy_github_app_flutter/page/login/login_page.dart';
import 'package:gsy_github_app_flutter/page/photoview_page.dart';
import 'package:gsy_github_app_flutter/page/welcome_page.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:gsy_github_app_flutter/redux/gsy_state.dart';
import 'package:redux/redux.dart';
import 'package:gsy_github_app_flutter/common/net/code.dart';

import 'common/utils/navigator_utils.dart';

Expand All @@ -28,7 +28,7 @@ class FlutterReduxApp extends StatefulWidget {
}

class _FlutterReduxAppState extends State<FlutterReduxApp>
with HttpErrorListener, NavigatorObserver {
with HttpErrorListener {
/// 创建Store,引用 GSYState 中的 appReducer 实现 Reducer 方法
/// initialState 初始化 State
final store = new Store<GSYState>(
Expand All @@ -53,6 +53,7 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
]);


NavigatorObserver navigatorObserver = NavigatorObserver();


@override
Expand All @@ -63,8 +64,8 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
/// MaterialApp 和 StoreProvider 的 context
/// 还可以获取到 navigator;
/// 比如在这里增加一个监听,如果 token 失效就退回登陆页。
navigator!.context;
navigator;
navigatorObserver.navigator!.context;
navigatorObserver.navigator;
});
}

Expand All @@ -76,7 +77,7 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
store: store,
child: new StoreBuilder<GSYState>(builder: (context, store) {
///使用 StoreBuilder 获取 store 中的 theme 、locale
store.state.platformLocale = WidgetsBinding.instance.window.locale;
store.state.platformLocale = WidgetsBinding.instance.platformDispatcher.locale;
Widget app = new MaterialApp(
navigatorKey: navKey,
///多语言实现代理
Expand All @@ -91,7 +92,7 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
],
locale: store.state.locale,
theme: store.state.themeData,
navigatorObservers: [this],
navigatorObservers: [navigatorObserver],

///命名式路由
/// "/" 和 MaterialApp 的 home 参数一个效果
Expand All @@ -104,16 +105,13 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
///⚠️ 这个是我故意的,如果不需要,可以去掉 pageContainer 或者不要用这里的 context
routes: {
WelcomePage.sName: (context) {
_context = context;
DebugLabel.showDebugLabel(context);
return WelcomePage();
},
HomePage.sName: (context) {
_context = context;
return NavigatorUtils.pageContainer(new HomePage(), context);
},
LoginPage.sName: (context) {
_context = context;
return NavigatorUtils.pageContainer(new LoginPage(), context);
},

Expand All @@ -138,16 +136,12 @@ class _FlutterReduxAppState extends State<FlutterReduxApp>
}),
);
}

}

mixin HttpErrorListener on State<FlutterReduxApp> {
StreamSubscription? stream;

///这里为什么用 _context 你理解吗?
///因为此时 State 的 context 是 FlutterReduxApp 而不是 MaterialApp
///所以如果直接用 context 是会获取不到 MaterialApp 的 Localizations 哦。
late BuildContext _context;

GlobalKey<NavigatorState> navKey = GlobalKey();

@override
Expand Down Expand Up @@ -211,3 +205,4 @@ mixin HttpErrorListener on State<FlutterReduxApp> {
toastLength: Toast.LENGTH_LONG);
}
}

9 changes: 5 additions & 4 deletions lib/common/utils/common_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ class CommonUtils {
store.dispatch(RefreshLocaleAction(locale));
}


/**
* 切换灰色
*/
Expand Down Expand Up @@ -306,9 +305,11 @@ class CommonUtils {
}

static copy(String? data, BuildContext context) {
Clipboard.setData(new ClipboardData(text: data));
Fluttertoast.showToast(
msg: GSYLocalizations.i18n(context)!.option_share_copy_success);
if (data != null) {
Clipboard.setData(new ClipboardData(text: data));
Fluttertoast.showToast(
msg: GSYLocalizations.i18n(context)!.option_share_copy_success);
}
}

static launchUrl(context, String? url) {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/utils/navigator_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class NavigatorUtils {
return MediaQuery(

///不受系统字体缩放影响
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window)
data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first)
.copyWith(textScaleFactor: 1),
child: NeverOverScrollIndicator(
needOverload: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/page/error_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ErrorPageState extends State<ErrorPage> {
@override
Widget build(BuildContext context) {
double width =
MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width;
MediaQueryData.fromView(View.of(context)).size.width;
return Container(
color: GSYColors.primaryValue,
child: new Center(
Expand Down
14 changes: 7 additions & 7 deletions lib/page/trend/trend_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ class TrendPageState extends State<TrendPage>
closedElevation: 0,
transitionType: ContainerTransitionType.fade,
openBuilder: (BuildContext context, VoidCallback _) {
return NavigatorUtils.pageContainer(RepositoryDetailPage(
reposViewModel.ownerName, reposViewModel.repositoryName), context);
return NavigatorUtils.pageContainer(
RepositoryDetailPage(
reposViewModel.ownerName, reposViewModel.repositoryName),
context);
},
tappable: true,
closedBuilder: (BuildContext _, VoidCallback openContainer) {
Expand Down Expand Up @@ -213,11 +215,9 @@ class TrendPageState extends State<TrendPage>

///空页面
Widget _buildEmpty() {
var statusBar =
MediaQueryData.fromWindow(WidgetsBinding.instance.window).padding.top;
var bottomArea = MediaQueryData.fromWindow(WidgetsBinding.instance.window)
.padding
.bottom;
var mediaQueryData = MediaQueryData.fromView(View.of(context));
var statusBar = mediaQueryData.padding.top;
var bottomArea = mediaQueryData.padding.bottom;
var height = MediaQuery.of(context).size.height -
statusBar -
bottomArea -
Expand Down
157 changes: 0 additions & 157 deletions lib/widget/network_cache_image.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/widget/pull/custom_bouncing_scroll_physics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CustomBouncingScrollPhysics extends ScrollPhysics {
@override
Simulation? createBallisticSimulation(
ScrollMetrics position, double velocity) {
final Tolerance tolerance = this.tolerance;
final Tolerance tolerance = toleranceFor(position);
if (velocity.abs() >= tolerance.velocity || position.outOfRange) {
return BouncingScrollSimulation(
spring: spring,
Expand Down
Loading

0 comments on commit 40faf94

Please sign in to comment.