Skip to content

Commit

Permalink
Upgrade Flutter dependencies and dart fix (thunder-app#1568)
Browse files Browse the repository at this point in the history
* chore: upgrade flutter dependencies, performed dart fix for some issues

* chore: additional dart fix

* lint: fix line formatting
  • Loading branch information
hjiangsu authored Sep 30, 2024
1 parent 0e50fd5 commit d53b57d
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 95 deletions.
4 changes: 2 additions & 2 deletions lib/comment/cubit/create_comment_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class CreateCommentCubit extends Cubit<CreateCommentState> {
Account? account = await fetchActiveProfileAccount();
if (account == null) return;

PictrsApi pictrs = PictrsApi(account.instance!);
PictrsApi pictrs = PictrsApi(account.instance);
List<String> urls = [];

emit(state.copyWith(status: CreateCommentStatus.imageUploadInProgress));

try {
for (String imageFile in imageFiles) {
PictrsUpload result = await pictrs.upload(filePath: imageFile, auth: account.jwt);
String url = "https://${account.instance!}/pictrs/image/${result.files[0].file}";
String url = "https://${account.instance}/pictrs/image/${result.files[0].file}";

urls.add(url);

Expand Down
2 changes: 0 additions & 2 deletions lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import 'package:thunder/core/enums/media_type.dart';
import 'package:thunder/core/enums/view_mode.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/theme/bloc/theme_bloc.dart';
import 'package:thunder/feed/bloc/feed_bloc.dart';
import 'package:thunder/feed/feed.dart';
import 'package:thunder/feed/view/feed_page.dart';
import 'package:thunder/shared/media_view.dart';
import 'package:thunder/shared/text/scalable_text.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/core/auth/bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
prefs.setString('active_profile_id', event.accountId);

// Check to see the instance settings (for checking if downvotes are enabled)
LemmyClient.instance.changeBaseUrl(account.instance!.replaceAll('https://', ''));
LemmyClient.instance.changeBaseUrl(account.instance.replaceAll('https://', ''));
LemmyApiV3 lemmy = LemmyClient.instance.lemmyApiV3;

GetSiteResponse getSiteResponse = await lemmy.run(GetSite(auth: account.jwt));
Expand Down Expand Up @@ -97,9 +97,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return emit(state.copyWith(status: AuthStatus.success, account: null, isLoggedIn: false));
}

if (activeAccount.username != null && activeAccount.jwt != null && activeAccount.instance != null) {
if (activeAccount.username != null && activeAccount.jwt != null) {
// Set lemmy client to use the instance
LemmyClient.instance.changeBaseUrl(activeAccount.instance!.replaceAll('https://', ''));
LemmyClient.instance.changeBaseUrl(activeAccount.instance.replaceAll('https://', ''));

// Check to see the instance settings (for checking if downvotes are enabled)
LemmyApiV3 lemmy = LemmyClient.instance.lemmyApiV3;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/auth/helpers/fetch_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Future<Account?> fetchActiveProfileAccount() async {

// Update the baseUrl if account was found
if (account?.instance != null && account!.instance != LemmyClient.instance.lemmyApiV3.host) {
LemmyClient.instance.changeBaseUrl(account.instance!.replaceAll('https://', ''));
LemmyClient.instance.changeBaseUrl(account.instance.replaceAll('https://', ''));
}

return account;
Expand Down
1 change: 0 additions & 1 deletion lib/feed/utils/community.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:thunder/account/models/account.dart';
import 'package:thunder/account/models/favourite.dart';
import 'package:thunder/core/auth/helpers/fetch_account.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:uuid/uuid.dart';

/// Logic to block a community
Future<BlockCommunityResponse> blockCommunity(int communityId, bool block) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/notification/utils/apns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void initAPNs({required StreamController<NotificationResponse> controller}) asyn

// TODO: Select accounts to enable push notifications
for (Account account in accounts) {
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.apn, token: token, jwt: account.jwt!, instance: account.instance!);
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.apn, token: token, jwt: account.jwt!, instance: account.instance);
if (!success) debugPrint("Failed to send device token to server for account ${account.id}. Skipping.");
}

Expand All @@ -48,7 +48,7 @@ void initAPNs({required StreamController<NotificationResponse> controller}) asyn

// TODO: Select accounts to enable push notifications
for (Account account in accounts) {
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.apn, token: token, jwt: account.jwt!, instance: account.instance!);
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.apn, token: token, jwt: account.jwt!, instance: account.instance);
if (!success) debugPrint("Failed to send device token to server for account ${account.id}. Skipping.");
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/notification/utils/navigate_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void navigateToNotificationReplyPage(BuildContext context, {required int? replyI

// Load the notifications
while (!doneFetching) {
final GetRepliesResponse getRepliesResponse = await (LemmyClient()..changeBaseUrl(account.instance!)).lemmyApiV3.run(GetReplies(
final GetRepliesResponse getRepliesResponse = await (LemmyClient()..changeBaseUrl(account.instance)).lemmyApiV3.run(GetReplies(
sort: CommentSortType.new_,
page: currentPage,
limit: 50,
Expand Down
2 changes: 1 addition & 1 deletion lib/notification/utils/unified_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void initUnifiedPushNotifications({required StreamController<NotificationRespons

// TODO: Select accounts to enable push notifications
for (Account account in accounts) {
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.unifiedPush, token: endpoint, jwt: account.jwt!, instance: account.instance!);
bool success = await sendAuthTokenToNotificationServer(type: NotificationType.unifiedPush, token: endpoint, jwt: account.jwt!, instance: account.instance);
if (!success) debugPrint("Failed to send device token to server for account ${account.id}. Skipping.");
}
},
Expand Down
4 changes: 2 additions & 2 deletions lib/post/cubit/create_post_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class CreatePostCubit extends Cubit<CreatePostState> {
Account? account = await fetchActiveProfileAccount();
if (account == null) return;

PictrsApi pictrs = PictrsApi(account.instance!);
PictrsApi pictrs = PictrsApi(account.instance);
List<String> urls = [];

isPostImage ? emit(state.copyWith(status: CreatePostStatus.postImageUploadInProgress)) : emit(state.copyWith(status: CreatePostStatus.imageUploadInProgress));

try {
for (String imageFile in imageFiles) {
PictrsUpload result = await pictrs.upload(filePath: imageFile, auth: account.jwt);
String url = "https://${account.instance!}/pictrs/image/${result.files[0].file}";
String url = "https://${account.instance}/pictrs/image/${result.files[0].file}";

urls.add(url);

Expand Down
2 changes: 0 additions & 2 deletions lib/post/utils/post.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:flutter/material.dart';

import 'package:lemmy_api_client/v3.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/settings/pages/accessibility_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_highlight/smooth_highlight.dart';
import 'package:thunder/community/utils/post_card_action_helpers.dart';

import 'package:thunder/core/enums/local_settings.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/settings/pages/fab_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:expandable/expandable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_highlight/smooth_highlight.dart';

import 'package:thunder/core/enums/fab_action.dart';
import 'package:thunder/core/enums/local_settings.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/settings/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _SettingsPageState extends State<SettingsPage> {
localSettings.length,
(index) => ListTile(
subtitle: Text(
"${l10n.getLocalSettingLocalization(localSettings[index].category!.toString())}${localSettings[index].subCategory == null ? '' : ' > ${l10n.getLocalSettingLocalization(localSettings[index].subCategory.toString())}'}"),
"${l10n.getLocalSettingLocalization(localSettings[index].category.toString())}${localSettings[index].subCategory == null ? '' : ' > ${l10n.getLocalSettingLocalization(localSettings[index].subCategory.toString())}'}"),
onTap: () {
navigateToSetting(context, localSettings[index]);
controller.closeView(null);
Expand Down
1 change: 0 additions & 1 deletion lib/shared/comment_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:thunder/comment/utils/comment.dart';
import 'package:thunder/shared/common_markdown_body.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/shared/cross_posts.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:thunder/core/enums/full_name.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/gesture_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ class _GestureFabState extends State<GestureFab> with SingleTickerProviderStateM
progress: _expandAnimation,
focus: isFabOpen && i == count - 1,
centered: widget.centered,
child: widget.children[i],
first: i == count - 1,
last: i == 0,
child: widget.children[i],
),
);
}
Expand Down
36 changes: 17 additions & 19 deletions lib/shared/multi_picker_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,26 @@ class MultiPickerItem extends StatelessWidget {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
...pickerItems
.map(
(p) => Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Tooltip(
message: p.label,
child: TextButton(
onPressed: p.onSelected,
style: TextButton.styleFrom(foregroundColor: p.backgroundColor),
child: Icon(
p.icon,
semanticLabel: p.label,
color: p.onSelected == null ? null : p.foregroundColor ?? theme.textTheme.bodyMedium?.color,
),
),
...pickerItems.map(
(p) => Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Tooltip(
message: p.label,
child: TextButton(
onPressed: p.onSelected,
style: TextButton.styleFrom(foregroundColor: p.backgroundColor),
child: Icon(
p.icon,
semanticLabel: p.label,
color: p.onSelected == null ? null : p.foregroundColor ?? theme.textTheme.bodyMedium?.color,
),
),
),
)
.toList(),
),
),
),
],
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/thunder/bloc/thunder_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:lemmy_api_client/v3.dart';

import 'package:shared_preferences/shared_preferences.dart';
import 'package:stream_transform/stream_transform.dart';
import 'package:thunder/account/models/account.dart';
import 'package:thunder/core/enums/action_color.dart';
import 'package:thunder/core/enums/browser_mode.dart';

Expand Down
3 changes: 1 addition & 2 deletions lib/thunder/pages/thunder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/core/singletons/preferences.dart';
import 'package:thunder/core/update/check_github_update.dart';
import 'package:thunder/feed/feed.dart';
import 'package:thunder/feed/widgets/feed_fab.dart';
import 'package:thunder/modlog/utils/navigate_modlog.dart';
import 'package:thunder/post/utils/post.dart';
import 'package:thunder/shared/common_markdown_body.dart';
Expand Down Expand Up @@ -219,7 +218,7 @@ class _ThunderState extends State<Thunder> {

if (activeAccount?.username != null && activeAccount?.jwt != null && activeAccount?.instance != null) {
// Set lemmy client to use the instance
LemmyClient.instance.changeBaseUrl(activeAccount!.instance!.replaceAll('https://', ''));
LemmyClient.instance.changeBaseUrl(activeAccount!.instance.replaceAll('https://', ''));
}

// If the incoming link is a custom URL, replace it back with https://
Expand Down
10 changes: 5 additions & 5 deletions lib/user/widgets/user_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Future<void> temporarilySwitchAccount(
if (communityActorId?.isNotEmpty == true && onCommunityChanged != null) {
CommunityView? resolvedCommunity;
try {
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance!).run(ResolveObject(q: communityActorId!));
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance).run(ResolveObject(q: communityActorId!));
resolvedCommunity = resolveObjectResponse.community;
} catch (e) {
// We'll just return null if we can't find it.
Expand All @@ -139,7 +139,7 @@ Future<void> temporarilySwitchAccount(
if (postActorId?.isNotEmpty == true && onPostChanged != null) {
PostView? resolvedPost;
try {
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance!).run(ResolveObject(q: postActorId!));
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance).run(ResolveObject(q: postActorId!));
resolvedPost = resolveObjectResponse.post;
if (resolvedPost != null) {
onPostChanged((await parsePostViews([resolvedPost])).first);
Expand All @@ -149,7 +149,7 @@ Future<void> temporarilySwitchAccount(
}
if (resolvedPost == null) {
// This is not allowed, so we must block the account switch.
showSnackbar(l10n.accountSwitchPostNotFound(newUser.instance!));
showSnackbar(l10n.accountSwitchPostNotFound(newUser.instance));
if (context.mounted) context.read<AuthBloc>().add(SwitchAccount(accountId: originalUser.id, reload: false));
}
}
Expand All @@ -158,7 +158,7 @@ Future<void> temporarilySwitchAccount(
if (parentCommentActorId?.isNotEmpty == true && onParentCommentChanged != null) {
CommentView? resolvedComment;
try {
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance!).run(ResolveObject(q: parentCommentActorId!));
final ResolveObjectResponse resolveObjectResponse = await LemmyApiV3(newUser.instance).run(ResolveObject(q: parentCommentActorId!));
resolvedComment = resolveObjectResponse.comment;
if (resolvedComment != null) {
onParentCommentChanged(resolvedComment);
Expand All @@ -168,7 +168,7 @@ Future<void> temporarilySwitchAccount(
}
if (resolvedComment == null) {
// This is not allowed, so we must block the accout switch.
showSnackbar(l10n.accountSwitchParentCommentNotFound(newUser.instance!));
showSnackbar(l10n.accountSwitchParentCommentNotFound(newUser.instance));
if (context.mounted) context.read<AuthBloc>().add(SwitchAccount(accountId: originalUser.id, reload: false));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/settings_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void shareSetting(BuildContext context, LocalSettings? setting, String descripti
if (setting == null) return;

final AppLocalizations l10n = AppLocalizations.of(context)!;
final String settingPath = '${l10n.getLocalSettingLocalization(setting.category!.toString())} > ${l10n.getLocalSettingLocalization(setting.subCategory.toString())} > $description';
final String settingPath = '${l10n.getLocalSettingLocalization(setting.category.toString())} > ${l10n.getLocalSettingLocalization(setting.subCategory.toString())} > $description';

Clipboard.setData(ClipboardData(text: '[Thunder Setting: $settingPath](thunder://setting-${setting.name})'));
showSnackbar('Setting link copied to clipboard!');
Expand Down
Loading

0 comments on commit d53b57d

Please sign in to comment.