move dependency management to file

pull/2342/head
Miguel Beltran 4 months ago
parent df928c657d
commit e978f4dcc0

@ -0,0 +1,26 @@
import 'package:compass_app/features/results/business/usecases/search_destination_usecase.dart';
import 'package:compass_app/features/results/data/destination_repository.dart';
import 'package:compass_app/features/results/presentation/results_viewmodel.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';
// Configure dependencies
List<SingleChildWidget> get providers {
// These dependencies don't need to be in the widget tree (yet?)
final destinationRepository = DestinationRepository();
final searchDestinationUsecase = SearchDestinationUsecase(
repository: destinationRepository,
);
// List of Providers
return [
// ViewModels are injected into Views using Provider
ChangeNotifierProvider(
create: (_) => ResultsViewModel(
searchDestinationUsecase: searchDestinationUsecase,
),
// create this ViewModel only when needed
lazy: true,
),
];
}

@ -1,29 +1,14 @@
import 'package:compass_app/features/results/business/usecases/search_destination_usecase.dart';
import 'package:compass_app/features/results/data/destination_repository.dart';
import 'package:compass_app/features/results/presentation/results_viewmodel.dart';
import 'package:compass_app/common/config/dependencies.dart';
import 'package:compass_app/routing/router.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
// Configure dependencies
// These dependencies don't need to be in the widget tree (yet?)
final repository = DestinationRepository();
final searchDestinationUsecase =
SearchDestinationUsecase(repository: repository);
runApp(
MultiProvider(
providers: [
// ViewModels are injected into Views using Provider
ChangeNotifierProvider(
create: (_) => ResultsViewModel(
searchDestinationUsecase: searchDestinationUsecase,
),
// create this ViewModel only when needed
lazy: true,
),
],
// Loading the default providers
// NOTE: We can load different configurations e.g. fakes
providers: providers,
child: const MainApp(),
),
);

Loading…
Cancel
Save