Home > Software design >  resize a widget in widget flutter
resize a widget in widget flutter

Time:02-06

i need some help i don't understand who to make a widget white 80 width blue and the child widget white width of 10 orange . i try this but all the widget seem to get width of 10 .what i doing bad ?

the LayoutBuilder is her cose i want my widget prompte width% of progress thk for ur help sry for my english


class ProgressBar extends StatelessWidget {
  const ProgressBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        return SizedBox(
            width: 80,
            height: 20,
            child: Container(
                color: Colors.blue,
                child: SizedBox(
                  width: 10,
                  height: 20,
                  child: Container(
                    color: Colors.orange,
                  ),
                )));
      },
    );
  }
}

CodePudding user response:

Use FittedBox like so:

return SizedBox(
  width: 80,
  height: 20,
  child: FittedBox(
     child: Container(
         color: Colors.blue,
         child: SizedBox(
           width: 10,
           height: 20,
           child: Container(
             color: Colors.orange
           ),
         ),
     ),
   ),
);
  •  Tags:  
  • Related