2022-12-14 17:33:38 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2023-01-26 09:10:23 +00:00
|
|
|
import 'package:lightmeter/interactors/metering_interactor.dart';
|
2023-08-14 10:25:37 +00:00
|
|
|
import 'package:lightmeter/providers/services_provider.dart';
|
2023-05-11 13:30:18 +00:00
|
|
|
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
|
|
|
import 'package:lightmeter/screens/metering/screen_metering.dart';
|
2023-11-02 16:40:47 +00:00
|
|
|
import 'package:lightmeter/screens/metering/utils/notifier_volume_keys.dart';
|
2022-12-18 09:03:41 +00:00
|
|
|
|
2023-01-29 16:57:47 +00:00
|
|
|
class MeteringFlow extends StatefulWidget {
|
2022-12-14 17:33:38 +00:00
|
|
|
const MeteringFlow({super.key});
|
|
|
|
|
2023-01-29 16:57:47 +00:00
|
|
|
@override
|
|
|
|
State<MeteringFlow> createState() => _MeteringFlowState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MeteringFlowState extends State<MeteringFlow> {
|
2022-12-14 17:33:38 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-08-14 10:25:37 +00:00
|
|
|
return MeteringInteractorProvider(
|
2023-06-04 11:04:04 +00:00
|
|
|
data: MeteringInteractor(
|
2023-08-14 10:25:37 +00:00
|
|
|
ServicesProvider.of(context).userPreferencesService,
|
|
|
|
ServicesProvider.of(context).caffeineService,
|
|
|
|
ServicesProvider.of(context).hapticsService,
|
|
|
|
ServicesProvider.of(context).permissionsService,
|
|
|
|
ServicesProvider.of(context).lightSensorService,
|
|
|
|
ServicesProvider.of(context).volumeEventsService,
|
2023-07-10 15:49:34 +00:00
|
|
|
)..initialize(),
|
2023-08-14 10:25:37 +00:00
|
|
|
child: MultiBlocProvider(
|
|
|
|
providers: [
|
|
|
|
BlocProvider(create: (_) => MeteringCommunicationBloc()),
|
|
|
|
BlocProvider(
|
|
|
|
create: (context) => MeteringBloc(
|
|
|
|
MeteringInteractorProvider.of(context),
|
|
|
|
VolumeKeysNotifier(ServicesProvider.of(context).volumeEventsService),
|
|
|
|
context.read<MeteringCommunicationBloc>(),
|
2023-01-21 10:37:49 +00:00
|
|
|
),
|
2023-08-14 10:25:37 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
child: const MeteringScreen(),
|
2023-01-21 10:37:49 +00:00
|
|
|
),
|
2022-12-14 17:33:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 10:25:37 +00:00
|
|
|
|
|
|
|
class MeteringInteractorProvider extends InheritedWidget {
|
|
|
|
final MeteringInteractor data;
|
|
|
|
|
|
|
|
const MeteringInteractorProvider({
|
|
|
|
required this.data,
|
|
|
|
required super.child,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
static MeteringInteractor of(BuildContext context) {
|
|
|
|
return context.findAncestorWidgetOfExactType<MeteringInteractorProvider>()!.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool updateShouldNotify(MeteringInteractorProvider oldWidget) => false;
|
|
|
|
}
|