Skip to content

Commit

Permalink
Make the overlay hidden when click the background
Browse files Browse the repository at this point in the history
  • Loading branch information
woin2ee committed Feb 20, 2025
1 parent de98ea6 commit cc82a19
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,26 @@ class FertilizerSelectionSection extends StatelessWidget {
FertilizerSelectionSection({
super.key,
SelectedFertilizerNotifier? notifier,
}) : _notifier = notifier ?? SelectedFertilizerNotifier(null);
OverlayPortalController? overlayController,
}) : _overlayController = overlayController ?? OverlayPortalController(),
_notifier = notifier ?? SelectedFertilizerNotifier(null);

final SelectedFertilizerNotifier _notifier;

final OverlayPortalController _overlayController;

@override
Widget build(BuildContext context) {
return Column(
spacing: 6,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const _FertilizerSelectionHeader(),
ChangeNotifierProvider.value(
value: _notifier,
MultiProvider(
providers: [
ChangeNotifierProvider.value(value: _notifier),
Provider.value(value: _overlayController),
],
child: const _FertilizerSelectionBody(),
),
],
Expand Down Expand Up @@ -230,9 +237,7 @@ class _GrowthFormulaButton extends StatefulWidget {
}

class _GrowthFormulaButtonState extends State<_GrowthFormulaButton> {
final _overlayController = OverlayPortalController();

Fertilizer _lastSelected = Items.growthFormulaStarter;
Fertilizer _lastSelectedFertilizer = Items.growthFormulaStarter;

@override
void initState() {
Expand All @@ -243,7 +248,7 @@ class _GrowthFormulaButtonState extends State<_GrowthFormulaButton> {
void _initLastSelectedFertilizer() {
final initialValue = widget.initialValue;
if (initialValue != null) {
_lastSelected = initialValue;
_lastSelectedFertilizer = initialValue;
}
}

Expand All @@ -265,9 +270,10 @@ class _GrowthFormulaButtonState extends State<_GrowthFormulaButton> {
@override
Widget build(BuildContext context) {
final selectedFertilizer = context.watch<SelectedFertilizerNotifier>();
final overlayController = context.read<OverlayPortalController>();

return OverlayPortal(
controller: _overlayController,
controller: overlayController,
overlayChildBuilder: (context) {
return Positioned(
top: _computeOverlayOffset(context).dy,
Expand All @@ -283,9 +289,9 @@ class _GrowthFormulaButtonState extends State<_GrowthFormulaButton> {
fertilizer: fertilizer,
onPressed: () {
selectedFertilizer.apply(fertilizer);
_overlayController.hide();
overlayController.hide();
setState(() {
_lastSelected = fertilizer;
_lastSelectedFertilizer = fertilizer;
});
},
);
Expand All @@ -297,8 +303,8 @@ class _GrowthFormulaButtonState extends State<_GrowthFormulaButton> {
);
},
child: _FertilizerIconButton(
fertilizer: _lastSelected,
onPressed: _overlayController.toggle,
fertilizer: _lastSelectedFertilizer,
onPressed: overlayController.toggle,
),
);
}
Expand Down
139 changes: 73 additions & 66 deletions lib/farm_page/edit_farm_set/farm_group_edit_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FarmGroupEditWindow extends StatefulWidget {

class _FarmGroupEditWindowState extends State<FarmGroupEditWindow> {
late final FarmGroupEditController controller;
final _overlayController = OverlayPortalController();

@override
void initState() {
Expand Down Expand Up @@ -67,72 +68,78 @@ class _FarmGroupEditWindowState extends State<FarmGroupEditWindow> {
Provider.value(value: this),
ChangeNotifierProvider.value(value: controller),
],
child: FittedBox(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18.0),
),
padding: const EdgeInsets.all(18.0),
child: IntrinsicHeight(
child: Row(
spacing: 20,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
spacing: 30,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const FertilizersInfoBox(),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
const CropsInfoBox(),
],
),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
Column(
spacing: 34,
children: [
const FarmGroupCanvas(),
ValueListenableBuilder(
valueListenable: controller.farmGroupModelNotifier,
builder: (context, value, child) => const AnalysisView()),
],
),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
Column(
spacing: 30.0,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const _TitleTextField(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8,
children: [
_buildFarmTypeSelectionBox(),
_buildFarmGroupTypeSelectionBox(),
],
),
CropSelectionSection(notifier: controller.selectedCropNotifier),
FertilizerSelectionSection(notifier: controller.selectedFertilizerNotifier),
const Row(
spacing: 20,
children: [
_CancelButton(),
_OkButton(),
],
),
],
),
],
child: GestureDetector(
onTap: () => _overlayController.hide(),
child: FittedBox(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18.0),
),
padding: const EdgeInsets.all(18.0),
child: IntrinsicHeight(
child: Row(
spacing: 20,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
spacing: 30,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const FertilizersInfoBox(),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
const CropsInfoBox(),
],
),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
Column(
spacing: 34,
children: [
const FarmGroupCanvas(),
ValueListenableBuilder(
valueListenable: controller.farmGroupModelNotifier,
builder: (context, value, child) => const AnalysisView()),
],
),
VerticalDivider(
width: 1.0,
color: Colors.grey.shade300,
),
Column(
spacing: 30.0,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const _TitleTextField(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8,
children: [
_buildFarmTypeSelectionBox(),
_buildFarmGroupTypeSelectionBox(),
],
),
CropSelectionSection(notifier: controller.selectedCropNotifier),
FertilizerSelectionSection(
notifier: controller.selectedFertilizerNotifier,
overlayController: _overlayController,
),
const Row(
spacing: 20,
children: [
_CancelButton(),
_OkButton(),
],
),
],
),
],
),
),
),
),
Expand Down

0 comments on commit cc82a19

Please sign in to comment.