Skip to content

add loading child widget to networkWidget #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ part 'stac_network_widget.g.dart';
abstract class StacNetworkWidget with _$StacNetworkWidget {
const factory StacNetworkWidget({
required StacNetworkRequest request,
Map<String, dynamic>? loading,
}) = _StacNetworkWidget;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add support for the error widget?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will add to the PR, I already added it but was too lazy to test it so did not include


factory StacNetworkWidget.fromJson(Map<String, dynamic> json) =>
_$StacNetworkWidgetFromJson(json);
factory StacNetworkWidget.fromJson(Map<String, dynamic> json) => _$StacNetworkWidgetFromJson(json);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$StacNetworkWidget {
StacNetworkRequest get request;
Map<String, dynamic>? get loading;

/// Create a copy of StacNetworkWidget
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -33,16 +34,18 @@ mixin _$StacNetworkWidget {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is StacNetworkWidget &&
(identical(other.request, request) || other.request == request));
(identical(other.request, request) || other.request == request) &&
const DeepCollectionEquality().equals(other.loading, loading));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, request);
int get hashCode => Object.hash(
runtimeType, request, const DeepCollectionEquality().hash(loading));

@override
String toString() {
return 'StacNetworkWidget(request: $request)';
return 'StacNetworkWidget(request: $request, loading: $loading)';
}
}

Expand All @@ -52,7 +55,7 @@ abstract mixin class $StacNetworkWidgetCopyWith<$Res> {
StacNetworkWidget value, $Res Function(StacNetworkWidget) _then) =
_$StacNetworkWidgetCopyWithImpl;
@useResult
$Res call({StacNetworkRequest request});
$Res call({StacNetworkRequest request, Map<String, dynamic>? loading});

$StacNetworkRequestCopyWith<$Res> get request;
}
Expand All @@ -71,12 +74,17 @@ class _$StacNetworkWidgetCopyWithImpl<$Res>
@override
$Res call({
Object? request = null,
Object? loading = freezed,
}) {
return _then(_self.copyWith(
request: null == request
? _self.request
: request // ignore: cast_nullable_to_non_nullable
as StacNetworkRequest,
loading: freezed == loading
? _self.loading
: loading // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
));
}

Expand All @@ -94,12 +102,23 @@ class _$StacNetworkWidgetCopyWithImpl<$Res>
/// @nodoc
@JsonSerializable()
class _StacNetworkWidget implements StacNetworkWidget {
const _StacNetworkWidget({required this.request});
const _StacNetworkWidget(
{required this.request, final Map<String, dynamic>? loading})
: _loading = loading;
factory _StacNetworkWidget.fromJson(Map<String, dynamic> json) =>
_$StacNetworkWidgetFromJson(json);

@override
final StacNetworkRequest request;
final Map<String, dynamic>? _loading;
@override
Map<String, dynamic>? get loading {
final value = _loading;
if (value == null) return null;
if (_loading is EqualUnmodifiableMapView) return _loading;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}

/// Create a copy of StacNetworkWidget
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -121,16 +140,18 @@ class _StacNetworkWidget implements StacNetworkWidget {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _StacNetworkWidget &&
(identical(other.request, request) || other.request == request));
(identical(other.request, request) || other.request == request) &&
const DeepCollectionEquality().equals(other._loading, _loading));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, request);
int get hashCode => Object.hash(
runtimeType, request, const DeepCollectionEquality().hash(_loading));

@override
String toString() {
return 'StacNetworkWidget(request: $request)';
return 'StacNetworkWidget(request: $request, loading: $loading)';
}
}

Expand All @@ -142,7 +163,7 @@ abstract mixin class _$StacNetworkWidgetCopyWith<$Res>
__$StacNetworkWidgetCopyWithImpl;
@override
@useResult
$Res call({StacNetworkRequest request});
$Res call({StacNetworkRequest request, Map<String, dynamic>? loading});

@override
$StacNetworkRequestCopyWith<$Res> get request;
Expand All @@ -162,12 +183,17 @@ class __$StacNetworkWidgetCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
$Res call({
Object? request = null,
Object? loading = freezed,
}) {
return _then(_StacNetworkWidget(
request: null == request
? _self.request
: request // ignore: cast_nullable_to_non_nullable
as StacNetworkRequest,
loading: freezed == loading
? _self._loading
: loading // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
));
}

Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class StacNetworkWidgetParser extends StacParser<StacNetworkWidget> {
String get type => WidgetType.networkWidget.name;

@override
StacNetworkWidget getModel(Map<String, dynamic> json) =>
StacNetworkWidget.fromJson(json);
StacNetworkWidget getModel(Map<String, dynamic> json) => StacNetworkWidget.fromJson(json);

@override
Widget parse(BuildContext context, StacNetworkWidget model) {
return Stac.fromNetwork(context: context, request: model.request);
return Stac.fromNetwork(
context: context,
request: model.request,
loadingWidget: (context) {
return Stac.fromJson(model.loading, context) ?? SizedBox();
},
);
}
}
Loading