Skip to content

Commit

Permalink
fix: nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed May 30, 2021
1 parent 4459255 commit 841a5d1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
5 changes: 0 additions & 5 deletions lib/home.dart
Expand Up @@ -191,20 +191,15 @@ class _HomeState extends State<Home> {
search,
me,
];
break;
case PlatformType.gitlab:
return [explore, group, search, me];
break;
case PlatformType.bitbucket:
return [explore, group, me];
break;
case PlatformType.gitea:
return [group, me];
break;
case PlatformType.gitee:
case PlatformType.gogs:
return [search, me];
break;
default:
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/scaffolds/list_stateful.dart
Expand Up @@ -26,7 +26,7 @@ class ListStatefulScaffold<T, K> extends StatefulWidget {
final Widget title;
final Widget Function()? actionBuilder;
final Widget Function(T payload) itemBuilder;
final Future<ListPayload<T, K>> Function(K cursor) fetch;
final Future<ListPayload<T, K>> Function(K? cursor) fetch;

ListStatefulScaffold({
required this.title,
Expand All @@ -41,7 +41,7 @@ class ListStatefulScaffold<T, K> extends StatefulWidget {
}

class _ListStatefulScaffoldState<T, K>
extends State<ListStatefulScaffold<T, K?>> {
extends State<ListStatefulScaffold<T, K>> {
bool loading = false;
bool loadingMore = false;
String error = '';
Expand Down
9 changes: 5 additions & 4 deletions lib/scaffolds/refresh_stateful.dart
Expand Up @@ -7,7 +7,8 @@ class RefreshStatefulScaffold<T> extends StatefulWidget {
final Widget title;
final Widget? Function(T data, void Function(T newData) setData) bodyBuilder;
final Future<T> Function() fetch;
final Widget? Function(T data, void Function(T newData) setData)? actionBuilder;
final Widget? Function(T data, void Function(T newData) setData)?
actionBuilder;
final Widget? action;
final canRefresh;

Expand All @@ -26,7 +27,7 @@ class RefreshStatefulScaffold<T> extends StatefulWidget {
}

class _RefreshStatefulScaffoldState<T>
extends State<RefreshStatefulScaffold<T?>> {
extends State<RefreshStatefulScaffold<T>> {
// bool _loading;
T? _data;
String _error = '';
Expand Down Expand Up @@ -60,7 +61,7 @@ class _RefreshStatefulScaffoldState<T>
Widget? get _action {
if (widget.action != null) return widget.action;
if (widget.actionBuilder == null || _data == null) return null;
return widget.actionBuilder!(_data, (v) {
return widget.actionBuilder!(_data!, (v) {
setState(() {
_data = v;
});
Expand All @@ -70,7 +71,7 @@ class _RefreshStatefulScaffoldState<T>
@override
Widget build(BuildContext context) {
Widget child = ErrorLoadingWrapper(
bodyBuilder: () => widget.bodyBuilder(_data, (v) {
bodyBuilder: () => widget.bodyBuilder(_data!, (v) {
setState(() {
_data = v;
});
Expand Down
6 changes: 3 additions & 3 deletions lib/scaffolds/tab_stateful.dart
Expand Up @@ -22,7 +22,7 @@ class TabStatefulScaffold<T> extends StatefulWidget {
_TabStatefulScaffoldState<T> createState() => _TabStatefulScaffoldState();
}

class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T?>> {
class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T>> {
late bool _loading;
T? _payload0;
T? _payload1;
Expand Down Expand Up @@ -90,7 +90,7 @@ class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T?>> {
title: widget.title,
action: widget.actionBuilder == null
? null
: widget.actionBuilder!(_payload, _refresh),
: widget.actionBuilder!(_payload!, _refresh),
tabs: widget.tabs,
activeTab: _activeTab,
onTabSwitch: (selected) async {
Expand All @@ -105,7 +105,7 @@ class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T?>> {
},
onRefresh: _refresh,
body: ErrorLoadingWrapper(
bodyBuilder: () => widget.bodyBuilder(_payload, _activeTab),
bodyBuilder: () => widget.bodyBuilder(_payload!, _activeTab),
error: _error,
loading: _payload == null,
reload: _refresh,
Expand Down
8 changes: 4 additions & 4 deletions lib/screens/gh_notification.dart
Expand Up @@ -20,7 +20,7 @@ class GhNotificationScreen extends StatefulWidget {
}

class GhNotificationScreenState extends State<GhNotificationScreen> {
Future<Map<String?, NotificationGroup>> fetchNotifications(int index) async {
Future<Map<String, NotificationGroup>> fetchNotifications(int index) async {
final ns = await context.read<AuthModel>().ghClient!.getJSON(
'/notifications?all=${index == 2}&participating=${index == 1}',
convert: (dynamic vs) =>
Expand All @@ -30,10 +30,10 @@ class GhNotificationScreenState extends State<GhNotificationScreen> {
context.read<NotificationModel>().setCount(ns.length);
}

Map<String?, NotificationGroup> _groupMap = {};
Map<String, NotificationGroup> _groupMap = {};

ns.forEach((item) {
final repo = item.repository!.fullName;
final repo = item.repository!.fullName ?? ''; // TODO: nullable
if (_groupMap[repo] == null) {
_groupMap[repo] = NotificationGroup(repo);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ ${item.key}: pullRequest(number: ${item.subject!.number}) {

@override
Widget build(context) {
return TabStatefulScaffold(
return TabStatefulScaffold<Map<String, NotificationGroup>>(
title: AppBarTitle(AppLocalizations.of(context)!.notification),
tabs: [
AppLocalizations.of(context)!.unread,
Expand Down
2 changes: 0 additions & 2 deletions lib/widgets/notification_item.dart
Expand Up @@ -42,7 +42,6 @@ class _NotificationItemState extends State<NotificationItem> {
default:
return _buildIcon(Octicons.person);
}
break;
case 'PullRequest':
switch (payload.state) {
case 'OPEN':
Expand All @@ -54,7 +53,6 @@ class _NotificationItemState extends State<NotificationItem> {
default:
return _buildIcon(Octicons.person);
}
break;
// color: Color.fromRGBO(0x6f, 0x42, 0xc1, 1),
case 'Release':
return _buildIcon(Octicons.tag);
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Expand Up @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -760,7 +760,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -802,7 +802,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
timeago:
dependency: "direct main"
description:
Expand Down

0 comments on commit 841a5d1

Please sign in to comment.