Expanded widget example in flutter

This Article is posted by seven.srikanth at 11/27/2022 1:59:27 AM



Hi All,
Here is a quick example on Expanded widget in flutter.
Here is the output from this example.
Here is the example code from main.dart file. 

import 'package:flutter/material.dart';
void main(List<String> args) {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @ override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}
class MyWidget extends StatelessWidget {
  const MyWidget({
    super.key,
  });
  @ override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: const [
          MyContainer(clr: Colors.red),
          Expanded(child: MyContainer(clr: Colors.green)),
          MyContainer(clr: Colors.red),
        ],
      ),
    );
  }
}
class MyContainer extends StatelessWidget {
  const MyContainer({
    super.key,
    required this.clr,
  });
  final Color clr;
  @ override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      width: 100,
      color: clr,
    );
  }
}
Thanks,
Srikanth

Tags: How to fill the widget in available space;








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com