Skip to content

Latest commit

 

History

History
47 lines (41 loc) · 917 Bytes

ex9-4.md

File metadata and controls

47 lines (41 loc) · 917 Bytes

9.4 Building with a Container

Example

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    const title = 'Container Widget Demo';
    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(title),
        ),
        body: const MyContainerWidget(),
      ),
    );
  }
}

class MyContainerWidget extends StatelessWidget {
  const MyContainerWidget({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: 200,
      width: 200,
      color: Colors.red[300],
      child: Container(
        height: 100,
        width: 100,
        color: Colors.yellow,
      ),
    );
  }
}