0 purchases
data repositories
DataRepositories #
The data_repositories package provides a simple and easy way to manage local and remote data. It can be used to read and write data to local storage, connect to remote data sources, automate data loading and processing, and handle errors and exceptions.
Usage #
dependencies:
data_repositories: ^0.0.3+1
dev_dependencies:
build_runner:
data_repository_generator: 0.0.3+2
copied to clipboard
Define and Generate #
import 'dart:async';
import 'package:data_repositories/data_repositories.dart';
import 'package:example/src/live/data/home/entity/quick_sale_entity.dart';
import 'package:example/src/live/erp/data/entity/home_entity/home_entity.dart';
import 'package:example/src/live/erp/data/repository/dao/home_dao.dart';
import 'package:example/src/test/data_repository/data/repository/rapid/quote/entity/cc_local_entity.dart';
import 'package:example/src/test/utils/cc_response/cc_response.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
part 'hom_repository.g.dart';
@DataRepository(
baseUrl: "https://ecservice.concung.com/home/",
version: 2,
entities: [
QuickSaleEntity,
ImplicitEntity,
HomeInfoEntity,
])
abstract class HomeRepository extends DataSource {
HomeDao get homeDao;
//[Remote]====================================================================
@Remote(
path: "getQuickSale?{path}",
method: HttpMethod.GET,
)
Future<CcResponse<QuickSaleEntity>> getQuickSaleImplicitRemote(
@Path() String path);
@Remote(
path: "getQuickSale?{path}",
method: HttpMethod.GET,
)
Future<CcResponse<QuickSaleEntity>> getQuickSaleExplicitRemote(
@Path() String path);
//[Remote Local ]=============================================================
@Remote(
path: "getQuickSale?{path}",
method: HttpMethod.GET,
)
@Local(
dataType: DataType.IMPLICIT,
version: 1,
tableName: "implicitQuickSaleEntity",
)
Future<CcResponse<QuickSaleEntity>> getQuickSaleImplicit(@Path() String path);
@Remote(
path: "getQuickSale?{path}",
method: HttpMethod.GET,
)
@Local(
dataType: DataType.EXPLICIT,
version: 1,
)
Future<CcResponse<QuickSaleEntity>> getQuickSaleExplicit(@Path() String path);
@Remote(
path: "getHomeInfo?{path}",
method: HttpMethod.GET,
)
@Local(
dataType: DataType.EXPLICIT,
version: 1,
)
Future<CcResponse<HomeInfoEntity>> getHomeInfoExplicit(@Path() String path);
@Remote(
path: "getQuickSale?{path}",
method: HttpMethod.GET,
)
@Local(
dataType: DataType.IMPLICIT,
tableName: "implicitQuickSaleEntity2",
version: 1,
)
Future<CcResponse<QuickSaleEntity>> getQuickSaleImplicit2(
@Path() String path);
@Remote(
path: "getHomeInfo?{path}",
method: HttpMethod.GET,
)
@Local(
dataType: DataType.IMPLICIT,
tableName: "implicitHomeInfoEntity2",
version: 1,
)
Future<CcResponse<HomeInfoEntity>> getHomeInfoImplicit2(@Path() String path);
//[Local Implicit]============================================================
@Local(
version: 1,
query: "SELECT * FROM QuickSaleEntity",
execute: Execute.QUERY,
)
Future<List<QuickSaleEntity>> getAll();
@Local(
version: 1,
query: "SELECT * FROM QuickSaleEntity WHERE realPrice <= 2000000",
execute: Execute.QUERY,
)
Future<List<QuickSaleEntity>> filterRealPrice();
@Local(
version: 1,
query: "SELECT * FROM QuickSaleEntity WHERE idCategory = :id",
execute: Execute.QUERY,
)
Future<QuickSaleEntity?> findId(int id);
//[Local Implicit End]========================================================
//[Local Implicit End]========================================================
@Local(
version: 1,
query: "SELECT * FROM implicitQuickSaleEntity",
execute: Execute.QUERY,
)
Future<List<ImplicitEntity>> getImplicitAll();
@Local(
version: 1,
query: "SELECT * FROM implicitQuickSaleEntity WHERE id = :id",
execute: Execute.QUERY,
)
Future<List<ImplicitEntity>> findImplicitId(int id);
//[Local Implicit End]========================================================
}
copied to clipboard
then run the generator
# dart
dart pub run build_runner build
# flutter
flutter pub run build_runner build
copied to clipboard
Use it #
test("getQuickSaleExplicit", () async {
final dio = Dio(); // Provide a dio instance
dio.options.headers['Demo-Header'] =
'demo header'; // config your dio headers globally
homeRepository = await $FloorHomeRepository
.databaseBuilder("home_controller_2.db")
.build(dio); // Creates the database and initializes it.
var path =
"checksum=18E9E28D1FF1DCD44D7DA7033214FFD8&customer_phone_login=0&device_os=2&id_category=0&id_customer=0&id_customer_login=0&id_district_login=&id_language=0&id_manufacturer=0&id_promotion_list=&id_session=2602223&id_utility=3&lasttime=0&n=30&p=1&version_app=4.0.21"; // Path parameters
var response = await homeRepository.getQuickSaleImplicit(path); // Result
response.print(); // Print result
});
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.