Skip to content

Instantly share code, notes, and snippets.

@osaxma
Created February 15, 2022 23:54
Show Gist options
  • Save osaxma/ca553e987d44656de6cb344b5cb772e5 to your computer and use it in GitHub Desktop.
Save osaxma/ca553e987d44656de6cb344b5cb772e5 to your computer and use it in GitHub Desktop.
// for SO question: https://stackoverflow.com/q/71134564/10976714
// ignore_for_file: avoid_function_literals_in_foreach_calls, avoid_print
import 'package:flutter/material.dart';
void main() {
runApp(const ContainerWidthExampleApp());
}
class ContainerWidthExampleApp extends StatelessWidget {
const ContainerWidthExampleApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
const MyHomePage({Key? key, required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: const Center(child: ContainerWidget()),
);
}
}
class ContainerWidget extends StatelessWidget {
const ContainerWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
SizedBox(
child: Container(
color: Colors.blue,
child: const Center( // <~~~ or `Align`
child: Text(
'You have pushed the',
),
),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment