refactor: Simplify repository imports and refactor dashboard navigation to use a dedicated helper method.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs
|
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||||
import 'package:firebase_data_connect/src/core/ref.dart';
|
|
||||||
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||||
import 'package:krow_domain/krow_domain.dart';
|
import 'package:krow_domain/krow_domain.dart';
|
||||||
import '../../domain/repositories/home_repository_interface.dart';
|
import '../../domain/repositories/home_repository_interface.dart';
|
||||||
@@ -9,13 +8,13 @@ import '../../domain/repositories/home_repository_interface.dart';
|
|||||||
/// This implementation follows the "Buffer Layer" pattern by using a dedicated
|
/// This implementation follows the "Buffer Layer" pattern by using a dedicated
|
||||||
/// connector repository from the data_connect package.
|
/// connector repository from the data_connect package.
|
||||||
class HomeRepositoryImpl implements HomeRepositoryInterface {
|
class HomeRepositoryImpl implements HomeRepositoryInterface {
|
||||||
|
|
||||||
HomeRepositoryImpl({
|
HomeRepositoryImpl({
|
||||||
dc.HomeConnectorRepository? connectorRepository,
|
dc.HomeConnectorRepository? connectorRepository,
|
||||||
dc.DataConnectService? service,
|
dc.DataConnectService? service,
|
||||||
}) : _connectorRepository = connectorRepository ??
|
}) : _connectorRepository =
|
||||||
dc.DataConnectService.instance.getHomeRepository(),
|
connectorRepository ??
|
||||||
_service = service ?? dc.DataConnectService.instance;
|
dc.DataConnectService.instance.getHomeRepository(),
|
||||||
|
_service = service ?? dc.DataConnectService.instance;
|
||||||
final dc.HomeConnectorRepository _connectorRepository;
|
final dc.HomeConnectorRepository _connectorRepository;
|
||||||
final dc.DataConnectService _service;
|
final dc.DataConnectService _service;
|
||||||
|
|
||||||
@@ -39,7 +38,8 @@ class HomeRepositoryImpl implements HomeRepositoryInterface {
|
|||||||
|
|
||||||
return await _service.run(() async {
|
return await _service.run(() async {
|
||||||
final String businessId = await _service.getBusinessId();
|
final String businessId = await _service.getBusinessId();
|
||||||
final QueryResult<dc.GetBusinessByIdData, dc.GetBusinessByIdVariables> businessResult = await _service.connector
|
final QueryResult<dc.GetBusinessByIdData, dc.GetBusinessByIdVariables>
|
||||||
|
businessResult = await _service.connector
|
||||||
.getBusinessById(id: businessId)
|
.getBusinessById(id: businessId)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
@@ -73,4 +73,3 @@ class HomeRepositoryImpl implements HomeRepositoryInterface {
|
|||||||
return _connectorRepository.getRecentReorders(businessId: businessId);
|
return _connectorRepository.getRecentReorders(businessId: businessId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import 'client_home_sheets.dart';
|
|||||||
/// This widget encapsulates the logic for rendering different dashboard
|
/// This widget encapsulates the logic for rendering different dashboard
|
||||||
/// widgets based on their unique identifiers and current state.
|
/// widgets based on their unique identifiers and current state.
|
||||||
class DashboardWidgetBuilder extends StatelessWidget {
|
class DashboardWidgetBuilder extends StatelessWidget {
|
||||||
|
|
||||||
/// Creates a [DashboardWidgetBuilder].
|
/// Creates a [DashboardWidgetBuilder].
|
||||||
const DashboardWidgetBuilder({
|
const DashboardWidgetBuilder({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -24,6 +23,7 @@ class DashboardWidgetBuilder extends StatelessWidget {
|
|||||||
required this.isEditMode,
|
required this.isEditMode,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// The unique identifier for the widget to build.
|
/// The unique identifier for the widget to build.
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
@@ -75,8 +75,7 @@ class DashboardWidgetBuilder extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
data,
|
data,
|
||||||
onSubmit: (Map<String, dynamic> submittedData) {
|
onSubmit: (Map<String, dynamic> submittedData) {
|
||||||
final String? dateStr =
|
final String? dateStr = submittedData['date']?.toString();
|
||||||
submittedData['date']?.toString();
|
|
||||||
if (dateStr == null || dateStr.isEmpty) {
|
if (dateStr == null || dateStr.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -84,12 +83,7 @@ class DashboardWidgetBuilder extends StatelessWidget {
|
|||||||
if (initialDate == null) {
|
if (initialDate == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Modular.to.navigate(
|
Modular.to.toOrdersSpecificDate(initialDate);
|
||||||
ClientPaths.orders,
|
|
||||||
arguments: <String, dynamic>{
|
|
||||||
'initialDate': initialDate.toIso8601String(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user