2022-10-24 20:25:38 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
2022-11-26 19:29:00 +00:00
|
|
|
import 'package:lightmeter/screens/settings/settings_page_route_builder.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-11-26 18:14:51 +00:00
|
|
|
import 'components/animated_surface/animated_surface.dart';
|
2022-10-29 11:01:15 +00:00
|
|
|
import 'components/bottom_controls/bottom_controls.dart';
|
2022-10-26 19:49:21 +00:00
|
|
|
import 'components/exposure_pairs_list/exposure_pairs_list.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
import 'components/topbar/topbar.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'metering_bloc.dart';
|
2022-11-26 18:14:51 +00:00
|
|
|
import 'metering_event.dart';
|
2022-10-29 18:02:45 +00:00
|
|
|
import 'metering_state.dart';
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-11-26 18:14:51 +00:00
|
|
|
class MeteringScreen extends StatefulWidget {
|
2022-11-26 19:29:00 +00:00
|
|
|
final AnimationController animationController;
|
|
|
|
|
|
|
|
const MeteringScreen({required this.animationController, super.key});
|
2022-10-24 20:25:38 +00:00
|
|
|
|
2022-11-26 18:14:51 +00:00
|
|
|
@override
|
|
|
|
State<MeteringScreen> createState() => _MeteringScreenState();
|
|
|
|
}
|
|
|
|
|
2022-11-26 19:29:00 +00:00
|
|
|
class _MeteringScreenState extends State<MeteringScreen> {
|
2022-11-26 18:14:51 +00:00
|
|
|
final _topBarKey = GlobalKey(debugLabel: 'TopBarKey');
|
|
|
|
final _middleAreaKey = GlobalKey(debugLabel: 'MiddleAreaKey');
|
|
|
|
final _bottomBarKey = GlobalKey(debugLabel: 'BottomBarKey');
|
|
|
|
|
|
|
|
bool _secondBuild = false;
|
|
|
|
late double _topBarHeight;
|
|
|
|
late double _middleAreaHeight;
|
|
|
|
late double _bottomBarHeight;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
_topBarHeight = _getHeight(_topBarKey);
|
|
|
|
_middleAreaHeight = _getHeight(_middleAreaKey);
|
|
|
|
_bottomBarHeight = _getHeight(_bottomBarKey);
|
|
|
|
setState(() {
|
|
|
|
_secondBuild = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-24 20:25:38 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.background,
|
2022-10-29 18:02:45 +00:00
|
|
|
body: BlocBuilder<MeteringBloc, MeteringState>(
|
|
|
|
builder: (context, state) {
|
2022-11-26 18:14:51 +00:00
|
|
|
return Stack(
|
2022-10-29 18:02:45 +00:00
|
|
|
children: [
|
2022-11-26 18:14:51 +00:00
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
if (_secondBuild) SizedBox(height: _topBarHeight) else _topBar(state),
|
|
|
|
Expanded(
|
|
|
|
key: _middleAreaKey,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: ExposurePairsList(state.exposurePairs),
|
|
|
|
),
|
|
|
|
const SizedBox(width: Dimens.grid16),
|
|
|
|
const Spacer()
|
|
|
|
],
|
2022-10-29 18:02:45 +00:00
|
|
|
),
|
2022-11-26 18:14:51 +00:00
|
|
|
),
|
2022-10-29 18:02:45 +00:00
|
|
|
),
|
2022-11-26 18:14:51 +00:00
|
|
|
if (_secondBuild) SizedBox(height: _bottomBarHeight) else _bottomBar(),
|
|
|
|
],
|
2022-10-29 18:02:45 +00:00
|
|
|
),
|
2022-11-26 18:14:51 +00:00
|
|
|
if (_secondBuild)
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: MeteringScreenAnimatedSurface.top(
|
2022-11-26 19:29:00 +00:00
|
|
|
controller: widget.animationController,
|
2022-11-26 18:14:51 +00:00
|
|
|
areaHeight: _topBarHeight,
|
|
|
|
overflowSize: _middleAreaHeight / 2,
|
|
|
|
child: _topBar(state),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (_secondBuild)
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
child: MeteringScreenAnimatedSurface.bottom(
|
2022-11-26 19:29:00 +00:00
|
|
|
controller: widget.animationController,
|
2022-11-26 18:14:51 +00:00
|
|
|
areaHeight: _bottomBarHeight,
|
|
|
|
overflowSize: _middleAreaHeight / 2,
|
|
|
|
child: _bottomBar(),
|
|
|
|
),
|
|
|
|
),
|
2022-10-29 18:02:45 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2022-10-24 20:25:38 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-11-26 18:14:51 +00:00
|
|
|
|
|
|
|
Widget _topBar(MeteringState state) {
|
|
|
|
return MeteringTopBar(
|
|
|
|
key: _topBarKey,
|
|
|
|
fastest: state.fastest,
|
|
|
|
slowest: state.slowest,
|
|
|
|
ev: state.ev,
|
|
|
|
iso: state.iso,
|
|
|
|
nd: state.nd,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _bottomBar() {
|
|
|
|
return MeteringBottomControls(
|
|
|
|
key: _bottomBarKey,
|
|
|
|
onSourceChanged: () {},
|
|
|
|
onMeasure: () => context.read<MeteringBloc>().add(const MeasureEvent()),
|
|
|
|
onSettings: () {
|
2022-11-26 19:29:00 +00:00
|
|
|
Navigator.push(context, SettingsPageRouteBuilder());
|
2022-11-26 18:14:51 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
double _getHeight(GlobalKey key) => key.currentContext!.size!.height;
|
2022-10-24 20:25:38 +00:00
|
|
|
}
|