Skip to content

Commit

Permalink
Optimize responsive layout effects;Update version to 1.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Stackflow committed Jul 23, 2024
1 parent af672e9 commit 278782a
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 127 deletions.
2 changes: 1 addition & 1 deletion lib/Models/user_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class BlogInfoWithHot {
imageDigitStamp: json['imageDigitStamp'],
imageProtected: json['imageProtected'],
imageStamp: json['imageStamp'],
ipLocation: json['ipLocation'],
ipLocation: json['ipLocation'] ?? "",
isOriginalAuthor: json['isOriginalAuthor'],
keyTag: json['keyTag'] ?? "",
novisible: json['novisible'],
Expand Down
14 changes: 8 additions & 6 deletions lib/Screens/Info/collection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:loftify/Api/user_api.dart';
import 'package:loftify/Resources/theme.dart';
import 'package:loftify/Utils/hive_util.dart';
import 'package:waterfall_flow/waterfall_flow.dart';

import '../../Models/post_detail_response.dart';
import '../../Utils/enums.dart';
Expand Down Expand Up @@ -146,12 +147,13 @@ class _CollectionScreenState extends State<CollectionScreen>
return ItemBuilder.buildLoadMoreNotification(
noMore: _noMore,
onLoad: _onLoad,
child: ListView.builder(
child: WaterfallFlow.extent(
maxCrossAxisExtent: 560,
physics: physics,
padding: const EdgeInsets.only(bottom: 20),
itemCount: _collectionList.length,
itemBuilder: (context, index) {
return _buildCollectionRow(
children: List.generate(
_collectionList.length,
(index) => _buildCollectionRow(
_collectionList[index],
verticalPadding: 8,
onTap: () {
Expand All @@ -165,8 +167,8 @@ class _CollectionScreenState extends State<CollectionScreen>
),
);
},
);
},
),
),
),
);
}
Expand Down
14 changes: 8 additions & 6 deletions lib/Screens/Info/grain_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:loftify/Models/recommend_response.dart';
import 'package:loftify/Resources/theme.dart';
import 'package:loftify/Screens/Post/grain_detail_screen.dart';
import 'package:loftify/Utils/hive_util.dart';
import 'package:waterfall_flow/waterfall_flow.dart';

import '../../Utils/enums.dart';
import '../../Utils/itoast.dart';
Expand Down Expand Up @@ -140,12 +141,13 @@ class _GrainScreenState extends State<GrainScreen>
return ItemBuilder.buildLoadMoreNotification(
noMore: _noMore,
onLoad: _onLoad,
child: ListView.builder(
child: WaterfallFlow.extent(
maxCrossAxisExtent: 560,
physics: physics,
padding: EdgeInsets.zero,
itemCount: _grainList.length,
itemBuilder: (context, index) {
return _buildGrainRow(
children: List.generate(
_grainList.length,
(index) => _buildGrainRow(
_grainList[index],
verticalPadding: 8,
onTap: () {
Expand All @@ -157,8 +159,8 @@ class _GrainScreenState extends State<GrainScreen>
),
);
},
);
},
),
),
),
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Screens/Info/user_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:loftify/Screens/Info/supporter_screen.dart';
import 'package:loftify/Screens/Post/post_detail_screen.dart';
import 'package:loftify/Utils/enums.dart';
import 'package:loftify/Utils/hive_util.dart';
import 'package:loftify/Utils/iprint.dart';
import 'package:loftify/Utils/uri_util.dart';
import 'package:loftify/Widgets/BottomSheet/input_bottom_sheet.dart';
import 'package:loftify/Widgets/Custom/subordinate_scroll_controller.dart';
Expand Down Expand Up @@ -85,7 +86,9 @@ class UserDetailScreenState extends State<UserDetailScreen>
_fetchShowCases();
setState(() {});
}
} catch (e) {
} catch (e, t) {
IPrint.debug(e);
IPrint.debug(t);
if (mounted) IToast.showTop("加载失败");
}
if (mounted) setState(() {});
Expand Down Expand Up @@ -487,7 +490,7 @@ class UserDetailScreenState extends State<UserDetailScreen>
fit: FlexFit.loose,
child: Text(
textAlign: TextAlign.center,
'性别: ${_fullBlogData!.blogInfo.gendar == 1 ? "男" : _fullBlogData!.blogInfo.gendar == 2 ? "女" : "保密"} | IP属地: ${_fullBlogData!.blogInfo.ipLocation}',
'性别: ${_fullBlogData!.blogInfo.gendar == 1 ? "男" : _fullBlogData!.blogInfo.gendar == 2 ? "女" : "保密"}${Utils.isNotEmpty(_fullBlogData!.blogInfo.ipLocation) ? " | IP属地: ${_fullBlogData!.blogInfo.ipLocation}" : ""}',
style: Theme.of(context)
.textTheme
.labelMedium
Expand Down
21 changes: 12 additions & 9 deletions lib/Screens/Navigation/dynamic_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ class SubscribeGrainTabState extends State<SubscribeGrainTab>
);
},
child: Container(
height: 96,
height: 125,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: Colors.transparent,
child: Row(
Expand All @@ -1399,8 +1399,8 @@ class SubscribeGrainTabState extends State<SubscribeGrainTab>
child: ItemBuilder.buildCachedImage(
imageUrl: item.grain.coverUrl,
context: context,
width: 80,
height: 80,
width: 100,
height: 100,
fit: BoxFit.cover,
showLoading: false,
),
Expand All @@ -1421,13 +1421,16 @@ class SubscribeGrainTabState extends State<SubscribeGrainTab>
?.apply(fontWeightDelta: 2),
),
const SizedBox(height: 6),
Text(
Utils.isNotEmpty(item.latestPost.title)
? item.latestPost.title
: item.latestPost.digest,
style: Theme.of(context).textTheme.labelMedium,
Flexible(
child: Text(
Utils.isNotEmpty(item.latestPost.title)
? item.latestPost.title
: item.latestPost.digest,
style: Theme.of(context).textTheme.labelMedium,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
),
const Spacer(),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/Screens/Navigation/webview_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class _WebviewScreenState extends State<WebviewScreen>
: const Color(0xFFF5F5F5),
appBar: showAppBar
? ItemBuilder.buildAppBar(
forceShowClose: true,
context: context,
leading: Icons.close_rounded,
backgroundColor: MyTheme.getBackground(context),
Expand Down
12 changes: 9 additions & 3 deletions lib/Screens/Post/post_detail_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';
import 'dart:math';

Expand Down Expand Up @@ -33,7 +34,6 @@ import '../../Resources/theme.dart';
import '../../Utils/app_provider.dart';
import '../../Utils/asset_util.dart';
import '../../Utils/constant.dart';
import '../../Utils/iprint.dart';
import '../../Utils/lottie_util.dart';
import '../../Utils/responsive_util.dart';
import '../../Utils/route_util.dart';
Expand Down Expand Up @@ -686,7 +686,10 @@ class _PostDetailScreenState extends State<PostDetailScreen>
.then((value) {
setState(() {
if (value['meta']['status'] != 200) {
IToast.showTop(value['meta']['desc'] ?? value['meta']['msg']);
if (Utils.isNotEmpty(value['meta']['desc']) &&
Utils.isNotEmpty(value['meta']['msg'])) {
IToast.showTop(value['meta']['desc'] ?? value['meta']['msg']);
}
if (value['meta']['status'] == 4071) {
Utils.validSlideCaptcha(context);
}
Expand Down Expand Up @@ -721,7 +724,10 @@ class _PostDetailScreenState extends State<PostDetailScreen>
.then((value) {
setState(() {
if (value['meta']['status'] != 200) {
IToast.showTop(value['meta']['desc'] ?? value['meta']['msg']);
if (Utils.isNotEmpty(value['meta']['desc']) &&
Utils.isNotEmpty(value['meta']['msg'])) {
IToast.showTop(value['meta']['desc'] ?? value['meta']['msg']);
}
if (value['meta']['status'] == 4071) {
Utils.validSlideCaptcha(context);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Screens/Setting/about_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class _AboutSettingScreenState extends State<AboutSettingScreen>
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ResponsiveUtil.isDesktop()
appBar: ResponsiveUtil.isLandscape()
? null
: ItemBuilder.buildSimpleAppBar(
transparent: true,
Expand Down
20 changes: 20 additions & 0 deletions lib/Screens/Setting/apperance_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:loftify/Resources/fonts.dart';
import 'package:loftify/Screens/Setting/select_theme_screen.dart';
import 'package:loftify/Utils/app_provider.dart';
import 'package:loftify/Utils/hive_util.dart';
import 'package:loftify/Utils/responsive_util.dart';
import 'package:provider/provider.dart';

import '../../Utils/enums.dart';
Expand All @@ -25,6 +26,8 @@ class AppearanceSettingScreen extends StatefulWidget {

class _AppearanceSettingScreenState extends State<AppearanceSettingScreen>
with TickerProviderStateMixin {
bool _enableLandscapeInTablet =
HiveUtil.getBool(HiveUtil.enableLandscapeInTabletKey, defaultValue: true);
bool _showRecommendVideo =
HiveUtil.getBool(HiveUtil.showRecommendVideoKey, defaultValue: false);
bool _showRecommendArticle =
Expand Down Expand Up @@ -128,6 +131,23 @@ class _AppearanceSettingScreenState extends State<AppearanceSettingScreen>
);
},
),
if (ResponsiveUtil.isTablet()) const SizedBox(height: 10),
if (ResponsiveUtil.isTablet())
ItemBuilder.buildRadioItem(
value: _enableLandscapeInTablet,
context: context,
title: "横屏时启用桌面端布局",
description: "更改后需要重启",
topRadius: true,
bottomRadius: true,
onTap: () {
setState(() {
_enableLandscapeInTablet = !_enableLandscapeInTablet;
appProvider.enableLandscapeInTablet =
_enableLandscapeInTablet;
});
},
),
const SizedBox(height: 10),
ItemBuilder.buildCaptionItem(context: context, title: "首页"),
ItemBuilder.buildRadioItem(
Expand Down
2 changes: 1 addition & 1 deletion lib/Screens/Setting/blacklist_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class _BlacklistSettingScreenState extends State<BlacklistSettingScreen>
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
width: 0.5,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/Screens/Setting/egg_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class _EggScreenState extends State<EggScreen> with TickerProviderStateMixin {
horizontal: 10, vertical: 10),
child: ItemBuilder.buildHtmlWidget(
context,
"&emsp;&emsp;恭喜你发现了我藏在Loftify中的<strong>小彩蛋</strong>!<br/>&emsp;&emsp;相信发现这个彩蛋的你已经很熟悉Loftify了,那么我先做个自我介绍吧。我呢,是一个喜欢用开发来方便自己的人,并经常乐此不疲地投入时间和精力去打磨修改自己的作品。由于实在无法忍受Lofter中烦人的广告,我在机缘巧合下重新拾起了Flutter开发Loftify并逐步适配Windows系统。<br/>&emsp;&emsp;在Loftify之前,我用原生安卓开发过一个完整的小项目CloudOTP,这款简洁的双因素身份验证器受到我室友的青睐,甚至他的同事还询问有没有IOS版本的。当听到这些时,我无疑是十分兴奋的,因为我第一次体会到自己的作品被他人认可的那种奇妙的感觉。兴许以后闲暇的时候,我也会用Flutter重构CloudOTP,将自己的作品呈现给更多喜欢它的人们。<br/>&emsp;&emsp;我总喜欢在我的作品中埋藏彩蛋,然而却都不够精彩和独一无二。而这个彩蛋的灵感呢,来源于Android 14系统,是我设计过的彩蛋中唯一差强人意的一个,以此献给使用Loftify的你,希望你喜欢这个彩蛋,也希望你能喜欢Loftify💕💕。",
"&emsp;&emsp;恭喜你发现了我藏在Loftify中的<strong>小彩蛋</strong>!<br/>&emsp;&emsp;相信发现这个彩蛋的你已经很熟悉Loftify了,那么我先做个自我介绍吧。我呢,是一个喜欢用开发来方便自己的人,并经常乐此不疲地投入时间和精力去打磨自己的作品。由于实在无法忍受Lofter中烦人的广告,我在机缘巧合下重新拾起了Flutter开发Loftify,并适配了平板设备和Windows系统。<br/>&emsp;&emsp;在Loftify之前,我用原生安卓开发过一个完整的小项目CloudOTP,这款简洁的双因素身份验证器受到我室友的青睐,甚至他的同事还询问有没有IOS版本的,这是我第一次体会到自己的作品被他人认可的那种奇妙的感觉。兴许以后闲暇的时候,我也会用Flutter重构CloudOTP,将自己的作品呈现给更多喜欢它的人们。<br/>&emsp;&emsp;我总喜欢在我的作品中埋藏彩蛋,然而却都不够精彩和独一无二。这个彩蛋的灵感呢,来源于Android 14系统,是我设计过的彩蛋中唯一差强人意的一个,以此献给使用Loftify的你,希望你喜欢这个彩蛋,也希望你能喜欢Loftify💕💕。",
textStyle: Theme.of(context).textTheme.bodyLarge,
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/Screens/Setting/tagshield_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class _TagShieldSettingScreenState extends State<TagShieldSettingScreen>
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
width: 0.5,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/Screens/Setting/userdynamicshield_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _UserDynamicShieldSettingScreenState
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
width: 0.5,
),
),
),
Expand Down
16 changes: 13 additions & 3 deletions lib/Screens/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ class MainScreenState extends State<MainScreen>
}

void onBottomNavigationBarItemTap(int index) {
bool canRefresh = (ResponsiveUtil.isMobile() ||
(ResponsiveUtil.isLandscape() && !canPopByKey)) &&
bool canRefresh = ((ResponsiveUtil.isMobile() &&
!ResponsiveUtil.isLandscape()) ||
(ResponsiveUtil.isLandscape() && !appProvider.canPopByProvider)) &&
_bottomBarSelectedIndex == index;
if (canRefresh) {
var page = _pageList[index];
Expand Down Expand Up @@ -366,7 +367,16 @@ class MainScreenState extends State<MainScreen>
@override
Widget build(BuildContext context) {
super.build(context);
return _buildBodyByPlatform();
return PopScope(
canPop: !appProvider.canPopByProvider,
onPopInvoked: (_) {
if (canPopByKey) {
desktopNavigatorState?.pop();
}
appProvider.canPopByProvider = canPopByKey;
},
child: _buildBodyByPlatform(),
);
}

_buildBodyByPlatform() {
Expand Down
14 changes: 14 additions & 0 deletions lib/Utils/app_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:loftify/Utils/responsive_util.dart';
import 'package:loftify/Widgets/Dialog/widgets/dialog_wrapper_widget.dart';
import 'package:tuple/tuple.dart';

Expand Down Expand Up @@ -40,6 +41,19 @@ class AppProvider with ChangeNotifier {
notifyListeners();
}

bool _enableLandscapeInTablet =
HiveUtil.getBool(HiveUtil.enableLandscapeInTabletKey);

bool get enableLandscapeInTablet => _enableLandscapeInTablet;

set enableLandscapeInTablet(bool value) {
_enableLandscapeInTablet = value;
HiveUtil.put(HiveUtil.enableLandscapeInTabletKey, value).then((value) {
ResponsiveUtil.restartApp(rootContext);
});
notifyListeners();
}

bool _canPopByProvider = false;

bool get canPopByProvider => _canPopByProvider;
Expand Down
1 change: 1 addition & 0 deletions lib/Utils/hive_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class HiveUtil {
static const String downloadSuccessActionKey = "downloadSuccessAction";

//Appearance
static const String enableLandscapeInTabletKey = "enableLandscapeInTablet";
static const String fontFamilyKey = "fontFamily";
static const String lightThemeIndexKey = "lightThemeIndex";
static const String darkThemeIndexKey = "darkThemeIndex";
Expand Down
6 changes: 4 additions & 2 deletions lib/Utils/responsive_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ class ResponsiveUtil {
return !kIsWeb &&
(Platform.isIOS || Platform.isAndroid) &&
sizeCondition &&
orientation == Orientation.portrait;
orientation == Orientation.landscape;
}

static bool isLandscape() {
return isWeb() || isDesktop() || isTablet();
return isWeb() ||
isDesktop() ||
(appProvider.enableLandscapeInTablet && isTablet());
}
}
11 changes: 8 additions & 3 deletions lib/Utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '../Widgets/Dialog/custom_dialog.dart';
import '../Widgets/Dialog/dialog_builder.dart';
import '../generated/l10n.dart';
import 'app_provider.dart';
import 'iprint.dart';
import 'itoast.dart';

class Utils {
Expand Down Expand Up @@ -490,6 +491,13 @@ class Utils {
String latestVersion = "0.0.0";
await GithubApi.getReleases("Robert-Stackflow", "Loftify")
.then((releases) async {
if (showLoading) {
CustomLoadingDialog.dismissLoading();
}
if (releases.isEmpty) {
if (showNoUpdateToast) IToast.showTop("检查更新失败");
return;
}
onGetReleases?.call(releases);
ReleaseItem? latestReleaseItem;
for (var release in releases) {
Expand All @@ -501,9 +509,6 @@ class Utils {
}
}
onGetLatestRelease?.call(latestVersion, latestReleaseItem!);
if (showLoading) {
CustomLoadingDialog.dismissLoading();
}
if (compareVersion(latestVersion, currentVersion) > 0) {
onUpdate?.call(latestVersion, latestReleaseItem!);
if (showUpdateDialog && latestReleaseItem != null) {
Expand Down
Loading

0 comments on commit 278782a

Please sign in to comment.