Skip to content

Commit

Permalink
updated flutter rocket package
Browse files Browse the repository at this point in the history
  • Loading branch information
M97Chahboun committed May 26, 2024
1 parent 18b0ebe commit 86be31f
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/models/photo_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Photo extends RocketModel<Photo> {
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
albumId = json[photoAlbumIdField];
id = json[photoIdField];
title = json[photoTitleField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/post_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Post extends RocketModel<Post> {
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
userId = json[postUserIdField];
id = json[postIdField];
title = json[postTitleField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Todos extends RocketModel<Todos> {
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
userId = json[todoUserIdField];
id = json[todoIdField];
title = json[todoTitleField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/todos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Todos extends RocketModel<Todos> {
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
userId = json[todosUserIdField];
id = json[todosIdField];
title = json[todosTitleField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class User extends RocketModel<User> {
}

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
id = json[userIdField];
name = json[userNameField];
username = json[userUsernameField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/user_submodel/address_submodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Address extends RocketModel<Address> {
}

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
street = json[addressStreetField];
suite = json[addressSuiteField];
city = json[addressCityField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/user_submodel/company_submodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Company extends RocketModel<Company> {
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
name = json[companyNameField];
catchPhrase = json[companyCatchPhraseField];
bs = json[companyBsField];
Expand Down
3 changes: 2 additions & 1 deletion lib/models/user_submodel/geo_submodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class Geo extends RocketModel<Geo> {
this.lng,
});
@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
void fromJson(Map<String, dynamic>? json, {bool isSub = false}) {
if (json == null) return;
lat = json[geoLatField];
lng = json[geoLngField];
super.fromJson(json, isSub: isSub);
Expand Down
2 changes: 1 addition & 1 deletion lib/views/photo_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PhotoExample extends StatelessWidget {
width: MediaQuery.of(context).size.width,
child: RocketView(
model: photo,
loader: const CircularProgressIndicator(),
onLoading: () => const CircularProgressIndicator(),
// get 5000 items
call: () => GetPhotos.getPhotos(photo),
builder: (context, modelState) {
Expand Down
2 changes: 1 addition & 1 deletion lib/views/post_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PostExample extends StatelessWidget {
// callType: CallType.callAsStream,
// secondsOfStream: 1,
// customized your loading (default widget is CircularProgressIndicator)
loader: const CircularProgressIndicator(),
onLoading: () => const CircularProgressIndicator(),

// handle errors
onError: (RocketException exception, Function() reload) {
Expand Down
2 changes: 1 addition & 1 deletion lib/views/todos_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TodosExample extends StatelessWidget {
body: RocketView(
model: todoModel,
call: () => GetTodos.getTodos(todoModel),
loader: const CircularProgressIndicator(),
onLoading: () => const CircularProgressIndicator(),
callType: CallType.callIfModelEmpty,
builder: (context, state) {
return ListView.builder(
Expand Down
2 changes: 1 addition & 1 deletion lib/views/user_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserExample extends StatelessWidget {
// your model
model: users,
// your widget for show data from model
loader: const CircularProgressIndicator(),
onLoading: () => const CircularProgressIndicator(),
builder: (context, modelState) {
return ListView.builder(
itemCount: users.all!.length,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_rocket: ^0.0.1
flutter_rocket: ^0.0.7


# The following adds the Cupertino Icons font to your application.
Expand Down
11 changes: 7 additions & 4 deletions test/fake_rocket_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ class RocketClientTest extends RocketClient {
this.dummyData,
) : super(url: '');
@override
Future request<T>(String endpoint,
@override
Future<RocketModel> request<T>(String endpoint,
{RocketModel<T>? model,
HttpMethods method = HttpMethods.get,
Function(dynamic data)? inspect,
List<String>? targetData,
RocketDataCallback? inspect,
List<String>? target,
RocketOnError? onError,
Map<String, dynamic>? data,
Map<String, dynamic>? params}) async {
Map<String, dynamic>? params,
RetryOptions retryOptions = const RetryOptions()}) async {
model!.state = RocketState.loading;
await Future.delayed(const Duration(seconds: 1));
try {
Expand Down

0 comments on commit 86be31f

Please sign in to comment.