-
-
Notifications
You must be signed in to change notification settings - Fork 81
feat(networkWidget): added loader and error widget support to networkwidget #373
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
Sharath-a26
wants to merge
1
commit into
StacDev:dev
Choose a base branch
from
Sharath-a26:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
examples/stac_gallery/assets/json/network_widget_example.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| { | ||
| "type": "scaffold", | ||
| "appBar": { | ||
| "type": "appBar", | ||
| "title": { | ||
| "type": "text", | ||
| "data": "Network Widget Example" | ||
| } | ||
| }, | ||
| "body": { | ||
| "type": "networkWidget", | ||
| "request": { | ||
| "actionType": "networkRequest", | ||
| "url": "https://httpbin.org/delay/2", | ||
| "method": "get" | ||
| }, | ||
| "loadingWidget": { | ||
| "type": "center", | ||
| "child": { | ||
| "type": "column", | ||
| "mainAxisAlignment": "center", | ||
| "children": [ | ||
| { | ||
| "type": "circularProgressIndicator" | ||
| }, | ||
| { | ||
| "type": "sizedBox", | ||
| "height": 16.0 | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "data": "Loading..." | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "errorWidget": { | ||
| "type": "center", | ||
| "child": { | ||
| "type": "column", | ||
| "mainAxisAlignment": "center", | ||
| "children": [ | ||
| { | ||
| "type": "icon", | ||
| "icon": "error", | ||
| "size": 48.0, | ||
| "color": "#E53935" | ||
| }, | ||
| { | ||
| "type": "sizedBox", | ||
| "height": 16.0 | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "data": "Failed to load", | ||
| "style": { | ||
| "fontSize": 18.0, | ||
| "fontWeight": "bold" | ||
| } | ||
| }, | ||
| { | ||
| "type": "sizedBox", | ||
| "height": 8.0 | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "data": "Please check your connection and try again" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/stac_core/lib/widgets/network_widget/stac_network_widget.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
packages/stac_core/test/widgets/network_widget/stac_network_widget_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we skip this test for now? It will be added again when we include full widget testing. |
||
| import 'package:stac_core/stac_core.dart'; | ||
|
|
||
| void main() { | ||
| group('StacNetworkWidget', () { | ||
| test('should create from JSON with loadingWidget and errorWidget', () { | ||
| // Arrange | ||
| const json = { | ||
| 'type': 'networkWidget', | ||
| 'request': { | ||
| 'actionType': 'networkRequest', | ||
| 'url': 'https://example.com/data', | ||
| 'method': 'get' | ||
| }, | ||
| 'loadingWidget': { | ||
| 'type': 'text', | ||
| 'data': 'Loading...' | ||
| }, | ||
| 'errorWidget': { | ||
| 'type': 'text', | ||
| 'data': 'Error occurred' | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| final widget = StacNetworkWidget.fromJson(json); | ||
|
|
||
| // Assert | ||
| expect(widget.request.url, equals('https://example.com/data')); | ||
| expect(widget.loadingWidget, isNotNull); | ||
| expect(widget.errorWidget, isNotNull); | ||
| }); | ||
|
|
||
| test('should create from JSON without optional widgets', () { | ||
| // Arrange | ||
| const json = { | ||
| 'type': 'networkWidget', | ||
| 'request': { | ||
| 'actionType': 'networkRequest', | ||
| 'url': 'https://example.com/data', | ||
| 'method': 'get' | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| final widget = StacNetworkWidget.fromJson(json); | ||
|
|
||
| // Assert | ||
| expect(widget.request.url, equals('https://example.com/data')); | ||
| expect(widget.loadingWidget, isNull); | ||
| expect(widget.errorWidget, isNull); | ||
| }); | ||
|
|
||
| test('should serialize to JSON with loadingWidget and errorWidget', () { | ||
| // Arrange | ||
| final widget = StacNetworkWidget( | ||
| request: StacNetworkRequest( | ||
| url: 'https://example.com/data', | ||
| method: 'get', | ||
| ), | ||
| loadingWidget: StacWidget.fromJson({'type': 'text', 'data': 'Loading...'}), | ||
| errorWidget: StacWidget.fromJson({'type': 'text', 'data': 'Error'}), | ||
| ); | ||
|
|
||
| // Act | ||
| final json = widget.toJson(); | ||
|
|
||
| // Assert | ||
| expect(json['request'], isNotNull); | ||
| expect(json['loadingWidget'], isNotNull); | ||
| expect(json['errorWidget'], isNotNull); | ||
| expect(json['loadingWidget']['data'], equals('Loading...')); | ||
| expect(json['errorWidget']['data'], equals('Error')); | ||
| }); | ||
|
|
||
| test('should serialize to JSON without optional widgets', () { | ||
| // Arrange | ||
| final widget = StacNetworkWidget( | ||
| request: StacNetworkRequest( | ||
| url: 'https://example.com/data', | ||
| method: 'get', | ||
| ), | ||
| ); | ||
|
|
||
| // Act | ||
| final json = widget.toJson(); | ||
|
|
||
| // Assert | ||
| expect(json['request'], isNotNull); | ||
| expect(json['loadingWidget'], isNull); | ||
| expect(json['errorWidget'], isNull); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the parse extension method instead from
StacWidgetParser. Like