0% found this document useful (0 votes)
2 views

Assignment java familiar questions-01

The document contains multiple Flutter exercises demonstrating the use of various button types including Container, TextButton, ElevatedButton, and OutlinedButton. Additionally, it includes an assignment that showcases an AlertDialog with a button to trigger it. Each exercise is structured with a main function and a MyApp class to build the user interface.

Uploaded by

kavana944922
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment java familiar questions-01

The document contains multiple Flutter exercises demonstrating the use of various button types including Container, TextButton, ElevatedButton, and OutlinedButton. Additionally, it includes an assignment that showcases an AlertDialog with a button to trigger it. Each exercise is structured with a main function and a MyApp class to build the user interface.

Uploaded by

kavana944922
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name: Kavana N

USN: 1MS23CS086 (Section B)


Department: CSE
Exercise-01
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromARGB(255, 106, 145, 177),
title: Text('Container Example'),
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
color: Colors.red,
width: 100,
height: 100,
margin: EdgeInsets.all(15),
),
Container(
color: Colors.green,
width: 100,
height: 100,
margin: EdgeInsets.all(15),
),
Container(
color: Colors.blue,
width: 100,
height: 100,
margin: EdgeInsets.all(15),
),
],
),
)),
);
}
}

Exercise-03
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(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('TextButton Example'),
),
body: Center(
child: TextButton(
onPressed: () {
print('Button Clicked!');
},
child: Text('Click Me')),
),
));
}
}

Exercise-04
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(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('ElevatedButton Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
print('Button Clicked!');
},
child: Text('Click Me')),
),
));
}
}

Exercise-05
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(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('OutlinedButton Example'),
),
body: Center(
child: OutlinedButton(
onPressed: () {
AlertDialog(
key: Key('Kavana N'),
);
},
child: Text(
'Click Me',
style: TextStyle(color: Colors.blue),
)),
),
));
}
}

Asssignment
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget{
void showAlertDialog(BuildContext context){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text("Alert Dialog"),
content: Text('Name: Kavana N'),
actions: <Widget>[
TextButton(
child:Text('Close'),
onPressed: (){
Navigator.of(context).pop();
},)
]
);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Alert Dialog Example'),),
body: Center(
child: ElevatedButton(
onPressed: (){
showAlertDialog(context);
},
child: Text('Click Me!'),
),)
);
}
}

You might also like