From 902c5a3515b923fb59e7c49e6f87eb1500f5d49a Mon Sep 17 00:00:00 2001 From: mchome Date: Sun, 12 Sep 2021 10:52:49 +0800 Subject: [PATCH] add orientation to material color picker --- lib/src/material_picker.dart | 77 ++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/lib/src/material_picker.dart b/lib/src/material_picker.dart index ff59748..6c4fb83 100644 --- a/lib/src/material_picker.dart +++ b/lib/src/material_picker.dart @@ -13,11 +13,13 @@ class MaterialPicker extends StatefulWidget { required this.pickerColor, required this.onColorChanged, this.enableLabel = false, + this.orientation, }) : super(key: key); final Color pickerColor; final ValueChanged onColorChanged; final bool enableLabel; + final Orientation? orientation; @override State createState() => _MaterialPickerState(); @@ -108,7 +110,9 @@ class _MaterialPickerState extends State { @override Widget build(BuildContext context) { Orientation _orientation = MediaQuery.of(context).orientation; - bool _isPortrait = _orientation == Orientation.portrait; + bool _isPortrait = (widget.orientation != null) + ? widget.orientation == Orientation.portrait + : _orientation == Orientation.portrait; Widget _colorList() { return Container( @@ -246,41 +250,48 @@ class _MaterialPickerState extends State { ); } + var _portraitPicker = SizedBox( + width: 350.0, + height: 500.0, + child: Row( + children: [ + _colorList(), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: _shadingList(), + ), + ), + ], + ), + ); + var _landscapePixker = SizedBox( + width: 500.0, + height: 300.0, + child: Column( + children: [ + _colorList(), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 12.0), + child: _shadingList(), + ), + ), + ], + ), + ); + if (widget.orientation != null) { + if (widget.orientation == Orientation.portrait) { + return _portraitPicker; + } else if (widget.orientation == Orientation.landscape) { + return _landscapePixker; + } + } switch (_orientation) { case Orientation.portrait: - return SizedBox( - height: 500.0, - width: 350.0, - child: Row( - children: [ - _colorList(), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12.0), - child: _shadingList(), - ), - ), - ], - ), - ); + return _portraitPicker; case Orientation.landscape: - return SizedBox( - width: 500.0, - height: 300.0, - child: Column( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 12.0), - child: _shadingList(), - ), - ), - _colorList(), - ], - ), - ); - default: - return Container(); + return _landscapePixker; } } }