Skip to content

Commit

Permalink
HECKIN CHONKER (null safety migration without scripts)
Browse files Browse the repository at this point in the history
  • Loading branch information
krawieck committed Apr 8, 2021
1 parent 9d90aa9 commit 8323553
Show file tree
Hide file tree
Showing 61 changed files with 894 additions and 879 deletions.
6 changes: 1 addition & 5 deletions lib/comment_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ extension on CommentSortType {
return (b, a) =>
a.comment.counts.score.compareTo(b.comment.counts.score);
}

throw Exception('unreachable');
}
}

class CommentTree {
CommentView comment;
List<CommentTree> children;

CommentTree(this.comment, [this.children]) {
children ??= [];
}
CommentTree(this.comment, [this.children = const []]);

/// takes raw linear comments and turns them into a CommentTree
static List<CommentTree> fromList(List<CommentView> comments) {
Expand Down
22 changes: 11 additions & 11 deletions lib/gen/assets.gen.dart

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

6 changes: 3 additions & 3 deletions lib/hooks/debounce.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Debounce {
final VoidCallback callback;

const Debounce({
@required this.loading,
@required this.callback,
required this.loading,
required this.callback,
});

void call() => callback();
Expand All @@ -24,7 +24,7 @@ Debounce useDebounce(
Duration delayDuration = const Duration(seconds: 1),
]) {
final loading = useState(false);
final timerHandle = useRef<Timer>(null);
final timerHandle = useRef<Timer?>(null);

cancel() {
timerHandle.current?.cancel();
Expand Down
10 changes: 5 additions & 5 deletions lib/hooks/delayed_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class DelayedLoading {
final VoidCallback cancel;

const DelayedLoading({
@required this.pending,
@required this.loading,
@required this.start,
@required this.cancel,
required this.pending,
required this.loading,
required this.start,
required this.cancel,
});
}

Expand All @@ -26,7 +26,7 @@ DelayedLoading useDelayedLoading(
[Duration delayDuration = const Duration(milliseconds: 500)]) {
final loading = useState(false);
final pending = useState(false);
final timerHandle = useRef<Timer>(null);
final timerHandle = useRef<Timer?>(null);

return DelayedLoading(
loading: loading.value,
Expand Down
9 changes: 2 additions & 7 deletions lib/hooks/infinite_scroll.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ import 'package:flutter_hooks/flutter_hooks.dart';

import '../widgets/infinite_scroll.dart';

InfiniteScrollController useInfiniteScrollController() {
final controller = useMemoized(() => InfiniteScrollController());

useEffect(() => controller.dispose, []);

return controller;
}
InfiniteScrollController useInfiniteScrollController() =>
useMemoized(() => InfiniteScrollController());
31 changes: 26 additions & 5 deletions lib/hooks/logged_in_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import 'stores.dart';
VoidCallback Function(
void Function(Jwt token) action, [
String message,
]) useLoggedInAction(String instanceHost, {bool any = false}) {
String? message,
]) useAnyLoggedInAction() {
final context = useContext();
final store = useAccountsStore();

return (action, [message]) {
if (any && store.hasNoAccount ||
!any && store.isAnonymousFor(instanceHost)) {
if (store.hasNoAccount) {
return () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(message ?? 'you have to be logged in to do that'),
Expand All @@ -31,7 +30,29 @@ VoidCallback Function(
));
};
}
final token = store.defaultTokenFor(instanceHost);
return () => action(store.defaultToken!);
};
}

VoidCallback Function(
void Function(Jwt token) action, [
String? message,
]) useLoggedInAction(String instanceHost) {
final context = useContext();
final store = useAccountsStore();

return (action, [message]) {
if (store.isAnonymousFor(instanceHost)) {
return () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(message ?? 'you have to be logged in to do that'),
action: SnackBarAction(
label: 'log in',
onPressed: () => goTo(context, (_) => AccountsConfigPage())),
));
};
}
final token = store.defaultTokenFor(instanceHost)!;
return () => action(token);
};
}
4 changes: 2 additions & 2 deletions lib/hooks/memo_future.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';

/// creates an [AsyncSnapshot] from the Future returned from the valueBuilder.
/// [keys] can be used to rebuild the Future
AsyncSnapshot<T> useMemoFuture<T>(Future<T> Function() valueBuilder,
[List<Object> keys = const <dynamic>[]]) =>
AsyncSnapshot<T?> useMemoFuture<T>(Future<T> Function() valueBuilder,
[List<Object> keys = const <Object>[]]) =>
useFuture(useMemoized<Future<T>>(valueBuilder, keys),
preserveState: false, initialData: null);
10 changes: 4 additions & 6 deletions lib/hooks/refreshable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'memo_future.dart';

class Refreshable<T> {
const Refreshable({@required this.snapshot, @required this.refresh})
: assert(snapshot != null),
assert(refresh != null);
const Refreshable({required this.snapshot, required this.refresh});

final AsyncSnapshot<T> snapshot;
final AsyncCallback refresh;
Expand All @@ -20,9 +18,9 @@ class Refreshable<T> {
///
/// `keys` will re-run the initial fetching thus yielding a
/// loading state in the AsyncSnapshot
Refreshable<T> useRefreshable<T>(AsyncValueGetter<T> fetcher,
[List<Object> keys = const <dynamic>[]]) {
final newData = useState<T>(null);
Refreshable<T?> useRefreshable<T>(AsyncValueGetter<T> fetcher,
[List<Object> keys = const <Object>[]]) {
final newData = useState<T?>(null);
final snapshot = useMemoFuture(() async {
newData.value = null;
return fetcher();
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export 'l10n_api.dart';
export 'l10n_from_string.dart';

abstract class LocaleSerde {
static Locale fromJson(String json) {
static Locale? fromJson(String? json) {
if (json == null) return null;

final lang = json.split('-');
Expand Down
40 changes: 20 additions & 20 deletions lib/l10n/l10n_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ extension SortTypeL10n on SortType {
String tr(BuildContext context) {
switch (this) {
case SortType.hot:
return L10n.of(context).hot;
return L10n.of(context)!.hot;
case SortType.new_:
return L10n.of(context).new_;
return L10n.of(context)!.new_;
case SortType.topYear:
return L10n.of(context).top_year;
return L10n.of(context)!.top_year;
case SortType.topMonth:
return L10n.of(context).top_month;
return L10n.of(context)!.top_month;
case SortType.topWeek:
return L10n.of(context).top_week;
return L10n.of(context)!.top_week;
case SortType.topDay:
return L10n.of(context).top_day;
return L10n.of(context)!.top_day;
case SortType.topAll:
return L10n.of(context).top_all;
return L10n.of(context)!.top_all;
case SortType.newComments:
return L10n.of(context).new_comments;
return L10n.of(context)!.new_comments;
case SortType.active:
return L10n.of(context).active;
return L10n.of(context)!.active;
case SortType.mostComments:
return L10n.of(context).most_comments;
return L10n.of(context)!.most_comments;
default:
throw Exception('unreachable');
}
Expand All @@ -35,13 +35,13 @@ extension PostListingTypeL10n on PostListingType {
String tr(BuildContext context) {
switch (this) {
case PostListingType.all:
return L10n.of(context).all;
return L10n.of(context)!.all;
case PostListingType.community:
return L10n.of(context).community;
return L10n.of(context)!.community;
case PostListingType.local:
return L10n.of(context).local;
return L10n.of(context)!.local;
case PostListingType.subscribed:
return L10n.of(context).subscribed;
return L10n.of(context)!.subscribed;
default:
throw Exception('unreachable');
}
Expand All @@ -52,17 +52,17 @@ extension SearchTypeL10n on SearchType {
String tr(BuildContext context) {
switch (this) {
case SearchType.all:
return L10n.of(context).all;
return L10n.of(context)!.all;
case SearchType.comments:
return L10n.of(context).comments;
return L10n.of(context)!.comments;
case SearchType.communities:
return L10n.of(context).communities;
return L10n.of(context)!.communities;
case SearchType.posts:
return L10n.of(context).posts;
return L10n.of(context)!.posts;
case SearchType.url:
return L10n.of(context).url;
return L10n.of(context)!.url;
case SearchType.users:
return L10n.of(context).users;
return L10n.of(context)!.users;
default:
throw Exception('unreachable');
}
Expand Down
Loading

0 comments on commit 8323553

Please sign in to comment.