ConstrainedBox Widget

 import "package:flutter/material.dart";


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

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "hello",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: const FlutterApp(),
);
}
}

class FlutterApp extends StatefulWidget {
const FlutterApp({super.key});

@override
State<StatefulWidget> createState() {
return FlutterAppState();
}
}

class FlutterAppState extends State<FlutterApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const UserAccountsDrawerHeader(
accountName: Text("John"),
accountEmail: Text("John123@google.com"),
currentAccountPicture: Icon(
Icons.account_circle,
size: 85,
),
),
ListTile(
leading: const Icon(Icons.message),
title: const Text("message"),
onTap: () {
Navigator.pop(context);
},
),
const Divider(thickness: 1, color: Colors.black),
ListTile(
leading: const Icon(Icons.account_circle),
title: const Text("profile"),
onTap: () {
Navigator.pop(context);
},
),
const Divider(thickness: 1, color: Colors.black),
ListTile(
leading: const Icon(Icons.settings),
title: const Text("settings"),
onTap: () {
Navigator.pop(context);
},
),
const Divider(thickness: 1, color: Colors.black),
ListTile(
leading: const Icon(Icons.help_outline),
title: const Text("Help & feedback"),
onTap: () {
Navigator.pop(context);
},
),
const Divider(thickness: 1, color: Colors.black),
ListTile(
leading: const Icon(Icons.restore_from_trash),
title: const Text("Trash"),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
appBar: AppBar(
title: const Text(
"Flutter Constraint box",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.grey,
),
/*By default,ConstrainedBox() contains only one child*/

body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 300,
minWidth: 200,
/*here,button will adopt minWidth & minHeight as specified*/
maxHeight: 300,
minHeight: 100,
),
/*child: const Text("Hello World.How are you ?.Welcome.Hello Flutter.Hello World.Next time we will meet in the morning",
style: TextStyle(fontSize: 21, overflow: TextOverflow.fade),)),*/

child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Click!",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.white),
),
),
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter