m3_lightmeter/lib/screens/timer/flow_timer.dart

68 lines
1.9 KiB
Dart
Raw Normal View History

2024-04-30 14:32:01 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
2024-05-02 15:11:53 +00:00
import 'package:lightmeter/data/models/exposure_pair.dart';
2024-05-03 10:43:45 +00:00
import 'package:lightmeter/interactors/timer_interactor.dart';
2024-04-30 14:32:01 +00:00
import 'package:lightmeter/providers/services_provider.dart';
2024-04-30 19:50:09 +00:00
import 'package:lightmeter/screens/timer/bloc_timer.dart';
2024-04-30 14:32:01 +00:00
import 'package:lightmeter/screens/timer/screen_timer.dart';
2024-05-04 16:51:56 +00:00
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
2024-04-30 14:32:01 +00:00
2024-05-04 16:51:56 +00:00
class TimerFlowArgs {
2024-05-02 15:11:53 +00:00
final ExposurePair exposurePair;
2024-05-04 16:51:56 +00:00
final IsoValue isoValue;
final NdValue ndValue;
const TimerFlowArgs({
required this.exposurePair,
required this.isoValue,
required this.ndValue,
});
}
class TimerFlow extends StatelessWidget {
final TimerFlowArgs args;
2024-05-03 08:50:35 +00:00
late final _duration =
2024-05-04 16:51:56 +00:00
Duration(milliseconds: (args.exposurePair.shutterSpeed.value * Duration.millisecondsPerSecond).toInt());
2024-05-02 15:11:53 +00:00
2024-05-04 16:51:56 +00:00
TimerFlow({required this.args, super.key});
2024-04-30 14:32:01 +00:00
@override
Widget build(BuildContext context) {
2024-05-03 10:43:45 +00:00
return TimerInteractorProvider(
data: TimerInteractor(
2024-05-03 09:26:00 +00:00
ServicesProvider.of(context).userPreferencesService,
ServicesProvider.of(context).hapticsService,
2024-05-03 10:43:45 +00:00
),
2024-05-03 09:26:00 +00:00
child: BlocProvider(
create: (context) => TimerBloc(
2024-05-03 10:43:45 +00:00
TimerInteractorProvider.of(context),
2024-05-03 09:26:00 +00:00
_duration,
2024-04-30 19:50:09 +00:00
),
2024-05-03 09:26:00 +00:00
child: TimerScreen(
2024-05-04 16:51:56 +00:00
exposurePair: args.exposurePair,
isoValue: args.isoValue,
ndValue: args.ndValue,
2024-05-03 09:26:00 +00:00
duration: _duration,
2024-04-30 19:57:02 +00:00
),
2024-04-30 14:32:01 +00:00
),
);
}
}
2024-05-03 10:43:45 +00:00
class TimerInteractorProvider extends InheritedWidget {
final TimerInteractor data;
2024-04-30 14:32:01 +00:00
2024-05-03 10:43:45 +00:00
const TimerInteractorProvider({
2024-04-30 14:32:01 +00:00
required this.data,
required super.child,
super.key,
});
2024-05-03 10:43:45 +00:00
static TimerInteractor of(BuildContext context) {
return context.findAncestorWidgetOfExactType<TimerInteractorProvider>()!.data;
2024-04-30 14:32:01 +00:00
}
@override
2024-05-03 10:43:45 +00:00
bool updateShouldNotify(TimerInteractorProvider oldWidget) => false;
2024-04-30 14:32:01 +00:00
}