Don't repeat Container

Hello,
I have many times it
is it possible to create a function if yes how can I do
exemple container()
thank you for your help

 child: Container(
                 width: 100.0,
                 height: 100.0,
                 decoration: BoxDecoration(
                   color: Colors.pink,
                   borderRadius: BorderRadius.only(
                     bottomLeft  : Radius.circular(20.0),
                     bottomRight : Radius.circular(20.0),
                     topLeft     : Radius.circular(20.0),
                     topRight    : Radius.circular(20.0),
                   ),
                     border: Border.all(
                         color: Colors.white,
                         width: 2.0
                     ),
                 ),
                 child: Center(
                   child: Text(
                     i.toString(),
                     style: TextStyle(color: Colors.white, fontSize: 26.0),
                   ),
                 ),
                 //color: Colors.pink,
               ),

Hi Carl,
you can use the refactoring tools in your IDE (Android Studio, VSCode) to extract widget:
Place the cursor on Container -> right-click -> Refactor… -> extract widget -> give it a meaningful name -> hit Enter

Then you can reuse the new widget constructor-function invocation where you need to repeat that container.

hth

1 Like

Hello Patrick I dont know this command :wink: thank you a lot for your help

1 Like