feat : new injection logic
test : some file :) chore : upgrade android gradle
This commit is contained in:
15
packages/livestock/lib/data/common/checkk_di_middleware.dart
Normal file
15
packages/livestock/lib/data/common/checkk_di_middleware.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
|
||||
|
||||
class CheckDiMiddleWare extends GetMiddleware {
|
||||
@override
|
||||
Future<GetNavConfig?> redirectDelegate(GetNavConfig route) async {
|
||||
return super.redirectDelegate(route);
|
||||
}
|
||||
|
||||
@override
|
||||
GetPage? onPageCalled(GetPage? page) {
|
||||
return super.onPageCalled(page);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/location/tmp_locations.dart';
|
||||
|
||||
class TmpLocalDataSource {
|
||||
Future<void> addLocations(List<TmpLocations> list) async {
|
||||
IsolatedBox<TmpLocations> box = await IsolatedHive.openBox<TmpLocations>('TmpBox');
|
||||
if (await box.isNotEmpty) {
|
||||
box.clear();
|
||||
}
|
||||
box.addAll(list);
|
||||
}
|
||||
|
||||
Future<List<TmpLocations>> getLocations() async {
|
||||
IsolatedBox<TmpLocations> box = await IsolatedHive.openBox<TmpLocations>('TmpBox');
|
||||
var res = await box.values;
|
||||
return res.toList();
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
|
||||
part 'car.g.dart';
|
||||
|
||||
|
||||
@HiveType(typeId: 50)
|
||||
class CarsLocal extends HiveObject {
|
||||
@HiveField(0)
|
||||
String? name;
|
||||
|
||||
@HiveField(1)
|
||||
String? price;
|
||||
|
||||
CarsLocal({this.name, this.price});
|
||||
|
||||
factory CarsLocal.fromJson(Map<String, dynamic> json) {
|
||||
return CarsLocal(name: json['name'] as String?, price: json['price'] as String?);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'name': name, 'price': price};
|
||||
}
|
||||
}
|
||||
|
||||
class Cars {
|
||||
String? name;
|
||||
String? price;
|
||||
|
||||
Cars({this.name, this.price});
|
||||
|
||||
factory Cars.fromJson(Map<String, dynamic> json) {
|
||||
return Cars(name: json['name'] as String?, price: json['price'] as String?);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'name': name, 'price': price};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
part 'tmp_locations.g.dart';
|
||||
|
||||
@HiveType(typeId: 100)
|
||||
class TmpLocations extends HiveObject{
|
||||
|
||||
@HiveField(0)
|
||||
double? lat;
|
||||
|
||||
|
||||
@HiveField(1)
|
||||
double? long;
|
||||
|
||||
TmpLocations({this.lat, this.long});
|
||||
}
|
||||
@@ -1,32 +1,34 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'car.dart';
|
||||
part of 'tmp_locations.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class CarsLocalAdapter extends TypeAdapter<CarsLocal> {
|
||||
class TmpLocationsAdapter extends TypeAdapter<TmpLocations> {
|
||||
@override
|
||||
final typeId = 50;
|
||||
final typeId = 100;
|
||||
|
||||
@override
|
||||
CarsLocal read(BinaryReader reader) {
|
||||
TmpLocations read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return CarsLocal(name: fields[0] as String?, price: fields[1] as String?);
|
||||
return TmpLocations()
|
||||
..lat = (fields[0] as num?)?.toDouble()
|
||||
..long = (fields[1] as num?)?.toDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, CarsLocal obj) {
|
||||
void write(BinaryWriter writer, TmpLocations obj) {
|
||||
writer
|
||||
..writeByte(2)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..write(obj.lat)
|
||||
..writeByte(1)
|
||||
..write(obj.price);
|
||||
..write(obj.long);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -35,7 +37,7 @@ class CarsLocalAdapter extends TypeAdapter<CarsLocal> {
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is CarsLocalAdapter &&
|
||||
other is TmpLocationsAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/captcha/captcha_response_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/live_tmp/livestock_model.dart';
|
||||
|
||||
abstract class LivestockRepository {
|
||||
@@ -11,4 +10,6 @@ abstract class LivestockRepository {
|
||||
|
||||
Future<bool> createTaggingLiveStock({required LivestockData data});
|
||||
|
||||
/* Future<List<LatLng>> getLocations();
|
||||
Future<void> addLocations(List<LatLng> latList);*/
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/data/services/network_status.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/local/tmp/tmp_local_data-source.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/livestock/livestock_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/location/tmp_locations.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/live_tmp/livestock_model.dart';
|
||||
|
||||
@@ -24,4 +29,35 @@ class LivestockRepositoryImp implements LivestockRepository {
|
||||
Future<bool> createTaggingLiveStock({required LivestockData data}) async {
|
||||
return await livestockRemote.createTaggingLiveStock(data: data);
|
||||
}
|
||||
/*
|
||||
@override
|
||||
Future<List<LatLng>> getLocations() async {
|
||||
if (NetworkStatus().isConnected.value) {
|
||||
return [
|
||||
LatLng(35.824891, 50.948025),
|
||||
LatLng(35.825000, 50.949000),
|
||||
LatLng(35.823000, 50.947000),
|
||||
LatLng(35.826000, 50.950000),
|
||||
LatLng(35.827000, 50.951000),
|
||||
LatLng(35.828000, 50.952000),
|
||||
LatLng(35.829000, 50.953000),
|
||||
LatLng(35.830000, 50.954000),
|
||||
LatLng(35.831000, 50.955000),
|
||||
LatLng(35.832000, 50.956000),
|
||||
LatLng(35.832000, 50.956055),
|
||||
];
|
||||
} else {
|
||||
*//*var res = await tmpLocalDataSource.getLocations();
|
||||
|
||||
return res.map((e) => LatLng(e.lat ?? 0.0, e.long ?? 0.0)).toList();*//*
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLocations(List<LatLng> latList) async {
|
||||
*//* await tmpLocalDataSource.addLocations(
|
||||
latList.map((e) => TmpLocations(lat: e.latitude, long: e.longitude)).toList(),
|
||||
);*//*
|
||||
iLog("it is done");
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/live_tmp/car.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/live_tmp/livestock_local_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/live_tmp/livestock_model.dart';
|
||||
import 'package:rasadyar_livestock/data/utils/mapper.dart';
|
||||
@@ -7,7 +6,7 @@ import 'package:rasadyar_livestock/data/utils/mapper.dart';
|
||||
class LiveStockStorageService extends GetxService {
|
||||
final String _liveStockBoxName = 'LiveStockBox';
|
||||
late IsolatedBox<LivestockLocalModel> _LiveStockbox;
|
||||
late IsolatedBox<CarsLocal> _carbox;
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
|
||||
@@ -3,27 +3,27 @@
|
||||
// Check in to version control
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/live_tmp/car.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/live_tmp/livestock_local_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/local/location/tmp_locations.dart';
|
||||
|
||||
extension HiveRegistrar on HiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(CarsLocalAdapter());
|
||||
registerAdapter(HerdLocalAdapter());
|
||||
registerAdapter(LivestockLocalAdapter());
|
||||
registerAdapter(LivestockLocalModelAdapter());
|
||||
registerAdapter(LocationLocalAdapter());
|
||||
registerAdapter(RancherLocalAdapter());
|
||||
registerAdapter(TmpLocationsAdapter());
|
||||
}
|
||||
}
|
||||
|
||||
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(CarsLocalAdapter());
|
||||
registerAdapter(HerdLocalAdapter());
|
||||
registerAdapter(LivestockLocalAdapter());
|
||||
registerAdapter(LivestockLocalModelAdapter());
|
||||
registerAdapter(LocationLocalAdapter());
|
||||
registerAdapter(RancherLocalAdapter());
|
||||
registerAdapter(TmpLocationsAdapter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ Future<void> setupLiveStockDI() async {
|
||||
IsolatedHive.registerAdapters();
|
||||
iLog("Sssssssssssssssssssss");
|
||||
final tokenService = Get.find<TokenStorageService>();
|
||||
Get.put<LiveStockStorageService>(LiveStockStorageService());
|
||||
|
||||
|
||||
|
||||
if (tokenService.baseurl.value == null) {
|
||||
@@ -31,7 +31,7 @@ Future<void> setupLiveStockDI() async {
|
||||
diLiveStock.registerLazySingleton<AppInterceptor>(
|
||||
() => AppInterceptor(
|
||||
refreshTokenCallback: () async {
|
||||
// Use lazy access to avoid circular dependency
|
||||
/* // Use lazy access to avoid circular dependency
|
||||
final authRepository = diLiveStock.get<AuthRepository>();
|
||||
final hasAuthenticated = await authRepository.hasAuthenticated();
|
||||
if (hasAuthenticated) {
|
||||
@@ -39,7 +39,7 @@ Future<void> setupLiveStockDI() async {
|
||||
authRequest: {'refresh': tokenService.refreshToken.value},
|
||||
);
|
||||
return newToken?.access;
|
||||
}
|
||||
}*/
|
||||
return null;
|
||||
},
|
||||
saveTokenCallback: (String newToken) async {
|
||||
|
||||
@@ -2,7 +2,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
|
||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart';
|
||||
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
|
||||
import 'package:rasadyar_livestock/presentation/page/root/logic.dart';
|
||||
|
||||
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
|
||||
|
||||
@@ -11,7 +14,6 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
String tileType = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
||||
RxDouble currentZoom = 15.0.obs;
|
||||
|
||||
|
||||
RxList<LatLng> allMarkers = <LatLng>[].obs;
|
||||
Rx<MapController> mapController = MapController().obs;
|
||||
RxList<ErrorLocationType> errorLocationType = RxList();
|
||||
@@ -19,19 +21,9 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
Timer? _debounceTimer;
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
RxList<LatLng> markerLocations = <LatLng>[
|
||||
LatLng(35.824891, 50.948025),
|
||||
LatLng(35.825000, 50.949000),
|
||||
LatLng(35.823000, 50.947000),
|
||||
LatLng(35.826000, 50.950000),
|
||||
LatLng(35.827000, 50.951000),
|
||||
LatLng(35.828000, 50.952000),
|
||||
LatLng(35.829000, 50.953000),
|
||||
LatLng(35.830000, 50.954000),
|
||||
LatLng(35.831000, 50.955000),
|
||||
LatLng(35.832000, 50.956000),
|
||||
LatLng(35.832000, 50.956055),
|
||||
].obs;
|
||||
RxList<LatLng> markerLocations = RxList();
|
||||
RootLogic rootLogic = Get.find<RootLogic>();
|
||||
late LivestockRepository repository ;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -67,6 +59,7 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
determineCurrentPosition();
|
||||
// getLoc();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -158,5 +151,14 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
return rawMarkers.where((marker) => distance(center, marker) <= radiusInMeters).toList();
|
||||
}
|
||||
|
||||
|
||||
/* Future<void> getLoc() async {
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
await safeCall(
|
||||
call: () async => repository.getLocations(),
|
||||
onSuccess: (result) {
|
||||
markerLocations.addAll(result);
|
||||
},
|
||||
onError: (error, stackTrace) {},
|
||||
);
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/data/services/network_status.dart';
|
||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
@@ -148,6 +149,16 @@ class MapWidget extends GetView<MapWidgetLogic> {
|
||||
);
|
||||
}, controller.currentLocation),
|
||||
|
||||
Positioned(
|
||||
top: 15,
|
||||
left: 20,
|
||||
child: ObxValue((status) {
|
||||
|
||||
|
||||
return Text("Connection: ${status.value}", style: TextStyle(fontSize: 20));
|
||||
}, NetworkStatus().isConnected),
|
||||
),
|
||||
|
||||
// Uncomment the following lines to enable the search widget
|
||||
/* Positioned(
|
||||
top: 10,
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
|
||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart';
|
||||
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
|
||||
import 'package:rasadyar_livestock/presentation/page/map/view.dart';
|
||||
import 'package:rasadyar_livestock/presentation/page/profile/view.dart';
|
||||
import 'package:rasadyar_livestock/presentation/page/request_tagging/view.dart';
|
||||
@@ -28,10 +34,49 @@ class RootLogic extends GetxController {
|
||||
];
|
||||
|
||||
RxInt currentIndex = 0.obs;
|
||||
|
||||
|
||||
TokenStorageService tokenService = Get.find<TokenStorageService>();
|
||||
|
||||
late StreamSubscription<List<ConnectivityResult>> connectivitySubscription;
|
||||
RxList<ConnectivityResult> connectivityResults = <ConnectivityResult>[].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
connectivitySubscription = Connectivity().onConnectivityChanged.listen((result) {
|
||||
if (result.isNotEmpty) {
|
||||
connectivityResults.assignAll(result);
|
||||
}
|
||||
});
|
||||
|
||||
/* GetIt.instance.allReady().then((value) async {
|
||||
await diLiveStock.get<LivestockRepositoryImp>().addLocations(generateRandomPoints());
|
||||
});*/
|
||||
}
|
||||
|
||||
List<LatLng> generateRandomPoints() {
|
||||
final Random random = Random();
|
||||
final double centerLat = 35.824891;
|
||||
final double centerLon = 50.948025;
|
||||
final double radiusKm = 1.0;
|
||||
final double kmToDegLat = 1 / 111.0; // 1 km ≈ 0.009° latitude
|
||||
final double kmToDegLon = 1 / (111.0 * cos(centerLat * pi / 180)); // Adjust for longitude
|
||||
|
||||
List<LatLng> points = [];
|
||||
for (int i = 0; i < 100; i++) {
|
||||
// Generate random angle (0 to 2π) and random radius (0 to 1 km, using sqrt for uniform distribution)
|
||||
double theta = random.nextDouble() * 2 * pi;
|
||||
double r =
|
||||
sqrt(random.nextDouble()) * radiusKm; // Square root for uniform distribution in circle
|
||||
// Convert polar coordinates to Cartesian, then to LatLng
|
||||
double deltaLat = r * cos(theta) * kmToDegLat;
|
||||
double deltaLon = r * sin(theta) * kmToDegLon;
|
||||
double newLat = centerLat + deltaLat;
|
||||
double newLon = centerLon + deltaLon;
|
||||
points.add(LatLng(newLat, newLon));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
@@ -40,7 +85,7 @@ class RootLogic extends GetxController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
connectivitySubscription.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class RootPage extends GetView<RootLogic> {
|
||||
final navigatorKey = Get.nestedKey(currentIndex);
|
||||
|
||||
if (currentIndex.value == 0 &&
|
||||
|
||||
navigatorKey != null &&
|
||||
navigatorKey.currentState != null) {
|
||||
if (navigatorKey.currentState!.canPop()) {
|
||||
|
||||
@@ -14,6 +14,8 @@ import 'package:rasadyar_livestock/presentation/page/tagging/view.dart';
|
||||
import 'package:rasadyar_livestock/presentation/widgets/base_page/logic.dart';
|
||||
import 'package:rasadyar_livestock/presentation/widgets/captcha/logic.dart';
|
||||
|
||||
import '../../injection/live_stock_di.dart';
|
||||
|
||||
part 'app_routes.dart';
|
||||
|
||||
sealed class LiveStockPages {
|
||||
|
||||
@@ -5,7 +5,7 @@ publish_to: 'none'
|
||||
# repository: https://github.com/my_org/my_repo
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
sdk: ^3.9.0
|
||||
|
||||
|
||||
dependencies:
|
||||
@@ -24,7 +24,7 @@ dev_dependencies:
|
||||
lints: ^6.0.0
|
||||
test: ^1.25.15
|
||||
##code generation
|
||||
build_runner: ^2.6.0
|
||||
build_runner: ^2.7.0
|
||||
hive_ce_generator: ^1.9.3
|
||||
freezed: ^3.2.0
|
||||
json_serializable: ^6.10.0
|
||||
|
||||
Reference in New Issue
Block a user