GardenPlanner/lib/widgets/content_widgets/control_bar.dart

101 lines
2.7 KiB
Dart
Raw Permalink Normal View History

2023-06-25 10:13:39 +02:00
import 'package:flutter/material.dart';
class Control extends StatelessWidget {
final bool showSpaceRequirements;
final Function(bool) onShowSpaceChanged;
final bool showImages;
final Function(bool) onImagesChanged;
final bool actionIsNeeded;
const Control({
Key? key,
required this.showSpaceRequirements,
required this.onShowSpaceChanged,
required this.showImages,
required this.onImagesChanged,
required this.actionIsNeeded,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.only(left: 1, right: 1, top: 10, bottom: 10),
decoration: _getDecoration(),
child: LayoutBuilder(
builder: (context, constraints) {
final smallSpace = constraints.maxWidth < 300;
if (smallSpace) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: _getControlElements(smallSpace),
);
} else {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: _getControlElements(smallSpace),
);
}
},
),
);
}
List<Widget> _getControlElements(bool reducedSpace) {
return [
if (actionIsNeeded)
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(Icons.warning),
if (!reducedSpace) const Text("Aktion nötig"),
],
),
if (!reducedSpace && !actionIsNeeded)
2023-06-25 10:15:30 +02:00
Row(
2023-06-25 10:13:39 +02:00
mainAxisAlignment: MainAxisAlignment.spaceAround,
2023-06-25 10:15:30 +02:00
children: const [
2023-06-25 10:13:39 +02:00
Text("Nichts zu tun"),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Text('Bilder / Text'),
Checkbox(
value: showImages,
onChanged: (value) => onImagesChanged(value ?? false),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Text('Pflanzposition'),
Checkbox(
value: showSpaceRequirements,
onChanged: (value) => onShowSpaceChanged(value ?? false),
),
],
),
];
}
BoxDecoration _getDecoration() {
return const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.topRight,
colors: [
Colors.green,
Colors.yellow,
],
),
borderRadius: BorderRadius.all(Radius.circular(40)),
);
}
}