diff --git a/assets/markdown/strategy.md b/assets/markdown/strategy.md index c0eccc0..4ba4b86 100644 --- a/assets/markdown/strategy.md +++ b/assets/markdown/strategy.md @@ -182,42 +182,25 @@ class _StrategyExampleState extends State { onClear: _clearOrder, ), const SizedBox(height: LayoutConstants.spaceM), - Stack( + Column( children: [ - AnimatedOpacity( - duration: const Duration(milliseconds: 500), - opacity: _order.items.isEmpty ? 1.0 : 0.0, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Your order is empty', - style: Theme.of(context).textTheme.titleLarge, - ), - ], - ), + if (_order.items.isEmpty) + Text( + 'Your order is empty', + style: Theme.of(context).textTheme.titleLarge, + ) + else + OrderItemsTable(orderItems: _order.items), + const SizedBox(height: LayoutConstants.spaceM), + ShippingOptions( + selectedIndex: _selectedStrategyIndex, + shippingOptions: _shippingCostsStrategyList, + onChanged: _setSelectedStrategyIndex, ), - AnimatedOpacity( - duration: const Duration(milliseconds: 500), - opacity: _order.items.isEmpty ? 0.0 : 1.0, - child: Column( - children: [ - OrderItemsTable( - orderItems: _order.items, - ), - const SizedBox(height: LayoutConstants.spaceM), - ShippingOptions( - selectedIndex: _selectedStrategyIndex, - shippingOptions: _shippingCostsStrategyList, - onChanged: _setSelectedStrategyIndex, - ), - OrderSummary( - shippingCostsStrategy: - _shippingCostsStrategyList[_selectedStrategyIndex], - order: _order, - ), - ], - ), + OrderSummary( + shippingCostsStrategy: + _shippingCostsStrategyList[_selectedStrategyIndex], + order: _order, ), ], ), diff --git a/lib/widgets/design_patterns/decorator/custom_pizza_selection.dart b/lib/widgets/design_patterns/decorator/custom_pizza_selection.dart index 76d0c89..aa8429f 100644 --- a/lib/widgets/design_patterns/decorator/custom_pizza_selection.dart +++ b/lib/widgets/design_patterns/decorator/custom_pizza_selection.dart @@ -20,29 +20,49 @@ class CustomPizzaSelection extends StatelessWidget { children: [ for (var i = 0; i < pizzaToppingsDataMap.length; i++) i == 0 - ? ChoiceChip( - label: const Text( - 'Pizza Base', - style: TextStyle(color: Colors.white), - ), + ? _ChoiceChip( + label: 'Pizza Base', selected: true, - selectedColor: Colors.black, onSelected: (_) {}, ) - : ChoiceChip( - label: Text( - pizzaToppingsDataMap[i]!.label, - style: TextStyle( - color: pizzaToppingsDataMap[i]!.selected - ? Colors.white - : Colors.black, - ), - ), + : _ChoiceChip( + label: pizzaToppingsDataMap[i]!.label, selected: pizzaToppingsDataMap[i]!.selected, - selectedColor: Colors.black, onSelected: (bool? selected) => onSelected(i, selected), ), ], ); } } + +class _ChoiceChip extends StatelessWidget { + const _ChoiceChip({ + required this.label, + required this.selected, + required this.onSelected, + }); + + final String label; + final bool selected; + final ValueSetter onSelected; + + @override + Widget build(BuildContext context) { + final color = selected ? Colors.white : Colors.black; + + return ChoiceChip( + color: MaterialStateProperty.resolveWith((states) { + if (states.contains(MaterialState.selected)) { + return Colors.black; + } + + return Colors.white; + }), + label: Text(label), + labelStyle: TextStyle(color: color), + checkmarkColor: color, + selected: selected, + onSelected: onSelected, + ); + } +} diff --git a/lib/widgets/design_patterns/strategy/strategy_example.dart b/lib/widgets/design_patterns/strategy/strategy_example.dart index b0b9a01..9d973ca 100644 --- a/lib/widgets/design_patterns/strategy/strategy_example.dart +++ b/lib/widgets/design_patterns/strategy/strategy_example.dart @@ -49,42 +49,25 @@ class _StrategyExampleState extends State { onClear: _clearOrder, ), const SizedBox(height: LayoutConstants.spaceM), - Stack( + Column( children: [ - AnimatedOpacity( - duration: const Duration(milliseconds: 500), - opacity: _order.items.isEmpty ? 1.0 : 0.0, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Your order is empty', - style: Theme.of(context).textTheme.titleLarge, - ), - ], - ), + if (_order.items.isEmpty) + Text( + 'Your order is empty', + style: Theme.of(context).textTheme.titleLarge, + ) + else + OrderItemsTable(orderItems: _order.items), + const SizedBox(height: LayoutConstants.spaceM), + ShippingOptions( + selectedIndex: _selectedStrategyIndex, + shippingOptions: _shippingCostsStrategyList, + onChanged: _setSelectedStrategyIndex, ), - AnimatedOpacity( - duration: const Duration(milliseconds: 500), - opacity: _order.items.isEmpty ? 0.0 : 1.0, - child: Column( - children: [ - OrderItemsTable( - orderItems: _order.items, - ), - const SizedBox(height: LayoutConstants.spaceM), - ShippingOptions( - selectedIndex: _selectedStrategyIndex, - shippingOptions: _shippingCostsStrategyList, - onChanged: _setSelectedStrategyIndex, - ), - OrderSummary( - shippingCostsStrategy: - _shippingCostsStrategyList[_selectedStrategyIndex], - order: _order, - ), - ], - ), + OrderSummary( + shippingCostsStrategy: + _shippingCostsStrategyList[_selectedStrategyIndex], + order: _order, ), ], ),