2. (a)Explore various Flutter widgets (Text, Image, Container, etc.).
# TEXT WIDGET
import 'package:flutter/[Link]';
void main() => runApp(const GeeksforGreeks());
class GeeksforGreeks extends StatelessWidget {
const GeeksforGreeks({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: [Link],
appBar: AppBar(
backgroundColor: [Link],
title: const Text("Welcome Screen"),
),
body: Container(
child: const Center(
child: Text("Hello World!!"),
),
),
),
);
}
Output:
// CONTAINER WIDGET
import 'package:flutter/[Link]';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("Container example"),
),
body: Container(
height: 200,
width: [Link],
color: [Link],
alignment: [Link],
margin: const [Link](20),
padding: const [Link](30),
transform: [Link](0.1),
child: const Text("Hello! i am inside a container!",
style: TextStyle(fontSize: 20)),
),
),
);
Output:
// IMAGE WIDGET
import 'package:flutter/[Link]';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Insert Image Demo')),
body: Center(
child: Column(
mainAxisAlignment: [Link],
children: <Widget>[
[Link](
'[Link]
height: 300,
width: 300,
fit: [Link],
),
],
),
),
),
);
Output:
2 b) Implement different layout structures using Row, Column and Stack widgets.
//ROW WIDGET
import 'package:flutter/[Link]';
//function to trigger build
void main() {
runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'GeeksForGeeks',
theme: ThemeData(primarySwatch: [Link]), // ThemeData
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
); // MaterialApp
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Flutter Row Example")), // AppBar
// App body consists of single Row
// Row consists of three children widgets
body: Row(
mainAxisAlignment: [Link],
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"ReactJS",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"Flutter",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"MYSQL",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
],
),
);
Output:
// COLUMN WIDGET
import 'package:flutter/[Link]';
//function to trigger build
void main() {
runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: [Link]), // ThemeData
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
); // MaterialApp
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Flutter Column Widget")), // AppBar
// App body consists of single Column
// Column consists of three children widgets
body: Column(
mainAxisAlignment: [Link],
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"ReactJS",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"Flutter",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: [Link](10),
color: [Link],
),
child: const Padding(
padding: [Link](8.0),
child: Text(
"MYSQL",
style: TextStyle(color: [Link], fontSize: 25),
),
),
),
],
), // Column
);
Output:
// STACK WIDGET
import 'package:flutter/[Link]';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Stack Demo'),
backgroundColor: [Link][400],
), //AppBar
body: Center(
child: SizedBox(
width: 300,
height: 300,
child: Center(
child: Stack(
children: <Widget>[
Container(
width: 300,
height: 300,
color: [Link],
), //Container
Container(
width: 250,
height: 250,
color: [Link],
), //Container
Container(
height: 200,
width: 200,
color: [Link],
), //Container
], //<Widget>[]
), //Stack
), //Center
), //SizedBox
), //Center
), //Scaffold
), //MaterialApp
);
Output: