reused BottomControlsBar

This commit is contained in:
Vadim 2024-05-03 11:26:00 +02:00
parent 7eb0ecde7f
commit 338a333a38
6 changed files with 135 additions and 176 deletions

View file

@ -1,48 +0,0 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/widget_bottom_controls.dart';
class MeteringBottomControlsProvider extends StatelessWidget {
final double? ev;
final double? ev100;
final bool isMetering;
final VoidCallback? onSwitchEvSourceType;
final VoidCallback onMeasure;
final VoidCallback onSettings;
const MeteringBottomControlsProvider({
required this.ev,
required this.ev100,
required this.isMetering,
required this.onSwitchEvSourceType,
required this.onMeasure,
required this.onSettings,
super.key,
});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return IconButtonTheme(
data: IconButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(scheme.surface),
elevation: const MaterialStatePropertyAll(4),
iconColor: MaterialStatePropertyAll(scheme.onSurface),
shadowColor: const MaterialStatePropertyAll(Colors.transparent),
surfaceTintColor: MaterialStatePropertyAll(scheme.surfaceTint),
fixedSize: const MaterialStatePropertyAll(Size(Dimens.grid48, Dimens.grid48)),
),
),
child: MeteringBottomControls(
ev: ev,
ev100: ev100,
isMetering: isMetering,
onSwitchEvSourceType: onSwitchEvSourceType,
onMeasure: onMeasure,
onSettings: onSettings,
),
);
}
}

View file

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart'; import 'package:lightmeter/screens/metering/components/bottom_controls/components/measure_button/widget_button_measure.dart';
import 'package:lightmeter/screens/shared/bottom_controls_bar/widget_bottom_controls_bar.dart';
class MeteringBottomControls extends StatelessWidget { class MeteringBottomControls extends StatelessWidget {
final double? ev; final double? ev;
@ -25,59 +25,31 @@ class MeteringBottomControls extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ClipRRect( return BottomControlsBar(
borderRadius: const BorderRadius.only( left: onSwitchEvSourceType != null
topLeft: Radius.circular(Dimens.borderRadiusL), ? IconButton(
topRight: Radius.circular(Dimens.borderRadiusL),
),
child: ColoredBox(
color: Theme.of(context).colorScheme.surface,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: Dimens.paddingL),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (onSwitchEvSourceType != null)
Expanded(
child: Center(
child: IconButton(
onPressed: onSwitchEvSourceType, onPressed: onSwitchEvSourceType,
icon: Icon( icon: Icon(
UserPreferencesProvider.evSourceTypeOf(context) != EvSourceType.camera UserPreferencesProvider.evSourceTypeOf(context) != EvSourceType.camera
? Icons.camera_rear ? Icons.camera_rear
: Icons.wb_incandescent, : Icons.wb_incandescent,
), ),
tooltip: tooltip: UserPreferencesProvider.evSourceTypeOf(context) != EvSourceType.camera
UserPreferencesProvider.evSourceTypeOf(context) != EvSourceType.camera
? S.of(context).tooltipUseCamera ? S.of(context).tooltipUseCamera
: S.of(context).tooltipUseLightSensor, : S.of(context).tooltipUseLightSensor,
),
),
) )
else : null,
const Spacer(), center: MeteringMeasureButton(
MeteringMeasureButton(
ev: ev, ev: ev,
ev100: ev100, ev100: ev100,
isMetering: isMetering, isMetering: isMetering,
onTap: onMeasure, onTap: onMeasure,
), ),
Expanded( right: IconButton(
child: Center(
child: IconButton(
onPressed: onSettings, onPressed: onSettings,
icon: const Icon(Icons.settings), icon: const Icon(Icons.settings),
tooltip: S.of(context).tooltipOpenSettings, tooltip: S.of(context).tooltipOpenSettings,
), ),
),
),
],
),
),
),
),
); );
} }
} }

View file

@ -8,7 +8,7 @@ import 'package:lightmeter/providers/equipment_profile_provider.dart';
import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart';
import 'package:lightmeter/screens/metering/bloc_metering.dart'; import 'package:lightmeter/screens/metering/bloc_metering.dart';
import 'package:lightmeter/screens/metering/components/bottom_controls/provider_bottom_controls.dart'; import 'package:lightmeter/screens/metering/components/bottom_controls/widget_bottom_controls.dart';
import 'package:lightmeter/screens/metering/components/camera_container/provider_container_camera.dart'; import 'package:lightmeter/screens/metering/components/camera_container/provider_container_camera.dart';
import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart'; import 'package:lightmeter/screens/metering/components/light_sensor_container/provider_container_light_sensor.dart';
import 'package:lightmeter/screens/metering/event_metering.dart'; import 'package:lightmeter/screens/metering/event_metering.dart';
@ -39,7 +39,7 @@ class MeteringScreen extends StatelessWidget {
), ),
), ),
BlocBuilder<MeteringBloc, MeteringState>( BlocBuilder<MeteringBloc, MeteringState>(
builder: (context, state) => MeteringBottomControlsProvider( builder: (context, state) => MeteringBottomControls(
ev: state is MeteringDataState ? state.ev : null, ev: state is MeteringDataState ? state.ev : null,
ev100: state is MeteringDataState ? state.ev100 : null, ev100: state is MeteringDataState ? state.ev100 : null,
isMetering: state.isMetering, isMetering: state.isMetering,

View file

@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
class BottomControlsBar extends StatelessWidget {
final Widget center;
final IconButton? left;
final IconButton? right;
const BottomControlsBar({
required this.center,
this.left,
this.right,
super.key,
});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return IconButtonTheme(
data: IconButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(scheme.surface),
elevation: const MaterialStatePropertyAll(4),
iconColor: MaterialStatePropertyAll(scheme.onSurface),
shadowColor: const MaterialStatePropertyAll(Colors.transparent),
surfaceTintColor: MaterialStatePropertyAll(scheme.surfaceTint),
fixedSize: const MaterialStatePropertyAll(Size(Dimens.grid48, Dimens.grid48)),
),
),
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(Dimens.borderRadiusL),
topRight: Radius.circular(Dimens.borderRadiusL),
),
child: ColoredBox(
color: Theme.of(context).colorScheme.surface,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: Dimens.paddingL),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
if (left != null) Expanded(child: Center(child: left)) else const Spacer(),
center,
if (right != null) Expanded(child: Center(child: right)) else const Spacer(),
],
),
),
),
),
),
);
}
}

View file

@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/interactors/metering_interactor.dart'; import 'package:lightmeter/interactors/metering_interactor.dart';
import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/providers/services_provider.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/timer/bloc_timer.dart'; import 'package:lightmeter/screens/timer/bloc_timer.dart';
import 'package:lightmeter/screens/timer/screen_timer.dart'; import 'package:lightmeter/screens/timer/screen_timer.dart';
@ -16,19 +15,7 @@ class TimerFlow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme; return MeteringInteractorProvider(
return IconButtonTheme(
data: IconButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(scheme.surface),
elevation: const MaterialStatePropertyAll(4),
iconColor: MaterialStatePropertyAll(scheme.onSurface),
shadowColor: const MaterialStatePropertyAll(Colors.transparent),
surfaceTintColor: MaterialStatePropertyAll(scheme.surfaceTint),
fixedSize: const MaterialStatePropertyAll(Size(Dimens.grid48, Dimens.grid48)),
),
),
child: MeteringInteractorProvider(
data: MeteringInteractor( data: MeteringInteractor(
ServicesProvider.of(context).userPreferencesService, ServicesProvider.of(context).userPreferencesService,
ServicesProvider.of(context).caffeineService, ServicesProvider.of(context).caffeineService,
@ -47,7 +34,6 @@ class TimerFlow extends StatelessWidget {
duration: _duration, duration: _duration,
), ),
), ),
),
); );
} }
} }

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:lightmeter/data/models/exposure_pair.dart'; import 'package:lightmeter/data/models/exposure_pair.dart';
import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/shared/bottom_controls_bar/widget_bottom_controls_bar.dart';
import 'package:lightmeter/screens/timer/bloc_timer.dart'; import 'package:lightmeter/screens/timer/bloc_timer.dart';
import 'package:lightmeter/screens/timer/components/text/widget_text_timer.dart'; import 'package:lightmeter/screens/timer/components/text/widget_text_timer.dart';
import 'package:lightmeter/screens/timer/components/timeline/widget_timeline_timer.dart'; import 'package:lightmeter/screens/timer/components/timeline/widget_timeline_timer.dart';
@ -77,14 +78,15 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
actions: [if (Navigator.of(context).canPop()) const CloseButton()], actions: [if (Navigator.of(context).canPop()) const CloseButton()],
), ),
body: SafeArea( body: SafeArea(
bottom: false,
child: Center( child: Center(
child: Padding(
padding: const EdgeInsets.all(Dimens.paddingL),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
const Spacer(), const Spacer(),
SizedBox.fromSize( Padding(
padding: const EdgeInsets.all(Dimens.paddingL),
child: SizedBox.fromSize(
size: Size.square(MediaQuery.sizeOf(context).width - Dimens.paddingL * 4), size: Size.square(MediaQuery.sizeOf(context).width - Dimens.paddingL * 4),
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: timelineAnimation, valueListenable: timelineAnimation,
@ -97,20 +99,16 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
), ),
), ),
), ),
),
const Spacer(), const Spacer(),
Row( BottomControlsBar(
children: [ left: IconButton(
Expanded(
child: Center(
child: IconButton(
onPressed: () { onPressed: () {
context.read<TimerBloc>().add(const ResetTimerEvent()); context.read<TimerBloc>().add(const ResetTimerEvent());
}, },
icon: const Icon(Icons.restore), icon: const Icon(Icons.restore),
), ),
), center: SizedBox.fromSize(
),
SizedBox.fromSize(
size: const Size.square(Dimens.grid72), size: const Size.square(Dimens.grid72),
child: BlocBuilder<TimerBloc, TimerState>( child: BlocBuilder<TimerBloc, TimerState>(
builder: (_, state) => FloatingActionButton( builder: (_, state) => FloatingActionButton(
@ -119,8 +117,7 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
if (timelineAnimation.value == 0) { if (timelineAnimation.value == 0) {
return; return;
} }
final event = final event = state is TimerStoppedState ? const StartTimerEvent() : const StopTimerEvent();
state is TimerStoppedState ? const StartTimerEvent() : const StopTimerEvent();
context.read<TimerBloc>().add(event); context.read<TimerBloc>().add(event);
}, },
child: AnimatedIcon( child: AnimatedIcon(
@ -130,15 +127,12 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
), ),
), ),
), ),
const Spacer(),
],
), ),
], ],
), ),
), ),
), ),
), ),
),
); );
} }