From 55d6069b847ee101c354383bd34cfaa5f30da6b1 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Thu, 2 May 2024 13:04:05 -0600 Subject: [PATCH] beauty builders --- lib/main.dart | 77 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 98245b5..2490436 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,6 +20,68 @@ class MyApp extends StatelessWidget { } } +/// +/// Shape Builder +/// +abstract class ShapeBuilder { + Widget build(Size size, Widget child) { + return Container( + height: size.height, + width: size.width, + decoration: BoxDecoration(shape: boxShape, color: shapeColor), + child: Center(child: child), + ); + } + + BoxShape get boxShape; + Color get shapeColor; +} + +class RedSquareBuilder extends ShapeBuilder { + @override + BoxShape get boxShape => BoxShape.rectangle; + + @override + Color get shapeColor => Colors.red; +} + +class BlueCircleBuilder extends ShapeBuilder { + @override + BoxShape get boxShape => BoxShape.circle; + + @override + Color get shapeColor => Colors.blue; +} + +/// +/// Message Builder (Writer seemed appropriate) +/// +abstract class MessageWriter { + Text write(String text); +} + +class HotMessageWriter extends MessageWriter { + @override + Text write(String text) => Text(text, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)); +} + +class ColdMessageWriter extends MessageWriter { + @override + Text write(String text) => Text(text, style: const TextStyle(color: Colors.white, fontSize: 14)); +} + +final List builders = [ + RedSquareBuilder(), + BlueCircleBuilder(), + RedSquareBuilder(), +]; + +final List writers = [ + ColdMessageWriter(), + HotMessageWriter(), + HotMessageWriter(), +]; + class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @@ -33,18 +95,19 @@ class _MyHomePageState extends State { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: const Text('Abstract Factory'), + title: const Text('Builders'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - 'some text', - style: Theme.of(context).textTheme.headlineMedium, + const Text('Builders!!'), + ...List.generate( + 3, + (index) => builders[index].build( + Size(80.0 * (index + 1), 90.0 * (index + 1)), + writers[index].write('build ${index + 1}'), + ), ), ], ),