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 _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) Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: const [ 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)), ); } }