Skip to content

Commit

Permalink
Update flutter rocket example (#120)
Browse files Browse the repository at this point in the history
* update flutter rocket example

* update flutter example tests

* bump version from 2.7.0+25 to 2.8.0+25 by fastlane plugin

* update dev workflow

* update flutter rocket package from pubspec

* format codes

* fixed tests issue
  • Loading branch information
M97Chahboun authored Jul 6, 2023
1 parent ef474af commit 126fb2f
Show file tree
Hide file tree
Showing 28 changed files with 525 additions and 262 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ jobs:
# Checkout Repo code
- name: Checkout Repo
uses: actions/checkout@v3
with:
token: ${{ secrets.REPO_TOKEN }}
# Setup the flutter environment.
- uses: subosito/flutter-action@v1
- uses: subosito/flutter-action@v2
- name: Get flutter dependencies.
run: flutter pub get

- name: Check for any formatting issues in the code.
run: flutter format --set-exit-if-changed .
run: dart format --set-exit-if-changed .

- name: Statically analyze the Dart code for any errors.
run: flutter analyze
run: dart analyze

- name: Run Tests
run: flutter test
88 changes: 30 additions & 58 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_ci_cd/views/counter_view.dart';
import 'package:flutter_ci_cd/views/mini_view.dart';
import 'package:flutter_ci_cd/views/photo_view.dart';
import 'package:flutter_ci_cd/views/post_view.dart';
import 'package:flutter_ci_cd/views/todos_view.dart';
import 'package:flutter_ci_cd/views/user_view.dart';
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

void main() {
runApp(const App());
Expand All @@ -25,21 +24,23 @@ class App extends StatelessWidget {
'/counter': (BuildContext context) => CounterExample(
title: "Counter",
),
'/user': (BuildContext context) => UserExample(
title: "10 Users",
),
'/post': (BuildContext context) => PostExample(
title: "100 Posts",
),
'/photo': (BuildContext context) => PhotoExample(
title: "5000 Photos",
),
'/user': (BuildContext context) => UserExample(
title: "10 Users",
'/todo': (BuildContext context) => TodosExample(
title: "200 Todos",
),
},
title: '🚀 MVCRocket 🚀 Package',
title: '🚀 Rocket Package 🚀',
theme: ThemeData(
primaryColor: Colors.brown,
appBarTheme: const AppBarTheme(backgroundColor: Colors.brown),
visualDensity: VisualDensity.adaptivePlatformDensity,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: MyApp());
}
Expand All @@ -48,71 +49,41 @@ class App extends StatelessWidget {
// ignore: must_be_immutable
class MyApp extends StatelessWidget {
final ValueNotifier<double> dx = ValueNotifier<double>(0.1);
late BuildContext cntx;
final List<String> exps = [
"MVCRocket Package",
"Link your app with API easily",
"One Package All Features",
"Make your work easy",
"this animation make by crazy code with timer"
];
int index = 0;
MyApp({Key? key}) : super(key: key) {
const String baseUrl = 'https://jsonplaceholder.typicode.com';
// create request object
RocketRequest request = RocketRequest(url: baseUrl);
// save it, for use it from any screen
Rocket.add(rocketRequestKey, request);
Timer.periodic(const Duration(milliseconds: 5), (timer) {
if (dx.value <=
MediaQuery.of(cntx).size.width +
(MediaQuery.of(cntx).size.width * 0.04)) {
dx.value += 0.5;
} else {
dx.value = -MediaQuery.of(cntx).size.width;
if (index < exps.length - 1) {
index++;
} else {
index = 0;
}
}
});
RocketClient request = RocketClient(url: baseUrl);
// save it, for use from any screen
Rocket.add(request);
}

@override
Widget build(BuildContext context) {
cntx = context;
return Scaffold(
appBar: AppBar(
title: const Text("🚀 MVCRocket 🚀 PACKAGE"),
title: const Text('🚀 Rocket Package 🚀'),
centerTitle: true,
),
body: Center(
child: SizedBox(
height: context.height * 0.6,
child: Column(
height: context.height * 0.8,
child: const Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ValueListenableBuilder(
valueListenable: dx,
builder: (context, _, __) {
return Transform.translate(
offset: Offset(dx.value, 1),
//dx: dx.value,
child: Text(
exps[index],
style: Theme.of(context)
.textTheme
.headline5!
.copyWith(fontWeight: FontWeight.bold),
),
);
}),
const Example("Mini View", "miniView"),
const Example("Counter View", "counter"),
const Example("100 Posts", "post"),
const Example("5000 Photos", "photo"),
const Example("10 Users", "user"),
Text(
'🚀 Rocket Package 🚀',
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.bold,
color: Colors.brown),
),
Example("Mini View", "miniView"),
Example("Counter View", "counter"),
Example("10 Users", "user"),
Example("100 Posts", "post"),
Example("5000 Photos", "photo"),
Example("200 Todos", "todo"),
],
),
),
Expand All @@ -130,6 +101,7 @@ class Example extends StatelessWidget {
width: context.width * 0.6,
height: context.height * 0.1,
child: TextButton(
key: Key(to),
child: Text(
title,
style: const TextStyle(
Expand Down
2 changes: 1 addition & 1 deletion lib/models/counter_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

class Counter extends RocketModel<Counter> {
int count;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/photo_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String photoAlbumIdField = "albumId";
const String photoIdField = "id";
Expand Down
2 changes: 1 addition & 1 deletion lib/models/post_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String postUserIdField = "userId";
const String postIdField = "id";
Expand Down
56 changes: 56 additions & 0 deletions lib/models/todo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter_rocket/flutter_rocket.dart';

const String todoUserIdField = "userId";
const String todoIdField = "id";
const String todoTitleField = "title";
const String todoCompletedField = "completed";

class Todos extends RocketModel<Todos> {
int? userId;
int? id;
String? title;
bool? completed;

Todos({
this.userId,
this.id,
this.title,
this.completed,
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
userId = json[todoUserIdField];
id = json[todoIdField];
title = json[todoTitleField];
completed = json[todoCompletedField];
super.fromJson(json, isSub: isSub);
}

void updateFields({
int? userIdField,
int? idField,
String? titleField,
bool? completedField,
}) {
userId = userIdField ?? userId;
id = idField ?? id;
title = titleField ?? title;
completed = completedField ?? completed;
rebuildWidget(fromUpdate: true);
}

@override
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {};
data[todoUserIdField] = userId;
data[todoIdField] = id;
data[todoTitleField] = title;
data[todoCompletedField] = completed;

return data;
}

@override
get instance => Todos();
}
56 changes: 56 additions & 0 deletions lib/models/todos.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter_rocket/flutter_rocket.dart';

const String todosUserIdField = "userId";
const String todosIdField = "id";
const String todosTitleField = "title";
const String todosCompletedField = "completed";

class Todos extends RocketModel<Todos> {
int? userId;
int? id;
String? title;
bool? completed;

Todos({
this.userId,
this.id,
this.title,
this.completed,
});

@override
void fromJson(Map<String, dynamic> json, {bool isSub = false}) {
userId = json[todosUserIdField];
id = json[todosIdField];
title = json[todosTitleField];
completed = json[todosCompletedField];
super.fromJson(json, isSub: isSub);
}

void updateFields({
int? userIdField,
int? idField,
String? titleField,
bool? completedField,
}) {
userId = userIdField ?? userId;
id = idField ?? id;
title = titleField ?? title;
completed = completedField ?? completed;
rebuildWidget(fromUpdate: true);
}

@override
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {};
data[todosUserIdField] = userId;
data[todosIdField] = id;
data[todosTitleField] = title;
data[todosCompletedField] = completed;

return data;
}

@override
get instance => Todos();
}
2 changes: 1 addition & 1 deletion lib/models/user_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

import 'user_submodel/address_submodel.dart';
import 'user_submodel/company_submodel.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/models/user_submodel/address_submodel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter_ci_cd/models/user_submodel/geo_submodel.dart';
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String addressStreetField = "street";
const String addressSuiteField = "suite";
Expand Down
2 changes: 1 addition & 1 deletion lib/models/user_submodel/company_submodel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String companyNameField = "name";
const String companyCatchPhraseField = "catchPhrase";
Expand Down
2 changes: 1 addition & 1 deletion lib/models/user_submodel/geo_submodel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String geoLatField = "lat";
const String geoLngField = "lng";
Expand Down
6 changes: 3 additions & 3 deletions lib/requests/photo_request.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter_ci_cd/models/photo_model.dart';
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String photosEndpoint = "photos";

class GetPhotos {
static Future getPhotos(Photo photoModel) => Rocket.get(rocketRequestKey)
.getObjData(photosEndpoint, photoModel, multi: true);
static Future getPhotos(Photo photoModel) =>
Rocket.get<RocketClient>().request(photosEndpoint, model: photoModel);
}
35 changes: 17 additions & 18 deletions lib/requests/post_request.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import 'package:flutter_ci_cd/models/post_model.dart';
import 'package:mvc_rocket/mvc_rocket.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String postsEndpoint = "posts";

class GetPosts {
static Future getPosts(Post postModel) =>
Rocket.get(rocketRequestKey).getObjData(
// endpoint
postsEndpoint,
// your model
postModel,
inspect: (d) {
return d;
},
// if you received data as List multi will be true & if data as map you not should to define multi its false as default
multi: true,
// parameters for send it with request
// params:{"key":"value"},
// inspect method for determine exact json use for generate your model in first step
// if your api send data directly without any supplement values you not should define it
// inspect:(data)=>data["response"]
);
static Future getPosts(Post postModel) {
return Rocket.get<RocketClient>().request(
// endpoint
postsEndpoint,
// your model
model: postModel,
inspect: (d) {
return d;
},
// parameters for send it with request
// params:{"key":"value"},
// inspect method for determine exact json use for generate your model in first step
// if your api send data directly without any supplement values you not should define it
// inspect:(data)=>data["response"]
);
}
}
9 changes: 9 additions & 0 deletions lib/requests/todos.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter_ci_cd/models/todos.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String todosEndpoint = "todos";

class GetTodos {
static Future gettodos(Todos todosModel) =>
Rocket.get<RocketClient>().request(todosEndpoint, model: todosModel);
}
9 changes: 9 additions & 0 deletions lib/requests/todos_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter_ci_cd/models/todo.dart';
import 'package:flutter_rocket/flutter_rocket.dart';

const String todosEndpoint = "todos";

class GetTodos {
static Future getTodos(Todos todosModel) =>
Rocket.get<RocketClient>().request(todosEndpoint, model: todosModel);
}
Loading

0 comments on commit 126fb2f

Please sign in to comment.