0% found this document useful (0 votes)
23 views22 pages

Android

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views22 pages

Android

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

Display "Hello World":


import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Hello World App'),
),
body: Center(
child: Text('Hello World 04-09-2024'),
),
),
);
}
}
2. Display the AppBar Code:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('AppBar Example 11-09-2024'),
),
body: Center(
child: Text('AppBar Code Displayed'),
),
),
);
}
}
3. Display Stateless and Stateful Widgets:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Stateless and Stateful Widgets 18-09-2024'),
),
body: Column(
children: [
StatelessExample(),
StatefulExample(),
],
),
),
);
}
}

class StatelessExample extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Text('This is a Stateless Widget');
}
}

class StatefulExample extends StatefulWidget {


@override
_StatefulExampleState createState() => _StatefulExampleState();
}

class _StatefulExampleState extends State<StatefulExample> {


int _counter = 0;

void _incrementCounter() {
setState(() {
_counter++;
});
}

@override
Widget build(BuildContext context) {
return Column(
children: [
Text('This is a Stateful Widget'),
Text('Counter: $_counter'),
ElevatedButton(
onPressed: _incrementCounter,
child: Text('Increment'),
),
], ); }}
4. Display Container Widget:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Container Widget 23-09-2024'),
),
body: Center(
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: Center(
child: Text(
'This is a Container',
style: TextStyle(color: Colors.white),
),
),
),
),
), ); }}
5. Remove Debug Banner:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false, // This removes the debug banner
home: Scaffold(
appBar: AppBar(
title: Text('Remove Debug Banner 30-09-2024'),
),
body: Center(
child: Text('Debug banner removed'),
),
),
);
}
}
6. Set Theme to Dark:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(), // This sets the theme to dark
home: Scaffold(
appBar: AppBar(
title: Text('Dark Theme 07-10-2024'),
),
body: Center(
child: Text('Dark theme applied'),
),
),
);
}
}
7. Display an Image:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Display Image 21-10-2024'),
),
body: Center(
child: Image.network(
'https://example.com/your-image-url.jpg', // Replace with your image URL
width: 200,
height: 200,
),
),
),
);
}
}
8. Display Screens Using Navigation:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: FirstScreen(),
);
}
}

class FirstScreen extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen 28-10-2024'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
child: Text('Go to Second Screen'),
),
),
);
}
}

class SecondScreen extends StatelessWidget {


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Screen 28-10-2024'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Back to First Screen'),
),
),
);
}
}
9. Display ScrollView:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('ScrollView 04-11-2024'),
),
body: SingleChildScrollView(
child: Column(
children: List.generate(50, (index) => Text('Item $index')),
),
),
),
);
}
}
10. Display RadioButton:
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {


@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


int _selectedValue = 1;

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('RadioButton 11-11-2024'),
),
body: Column(
children: [
RadioListTile<int>(
title: Text('Option 1'),
value: 1,
groupValue: _selectedValue,
onChanged: (value) {
setState(() {
_selectedValue = value!;
});
},
),
RadioListTile<int>(
title: Text('Option 2'),
value: 2,
groupValue: _selectedValue,
onChanged: (value) {
setState(() {
_selectedValue = value!;
});
},
),
RadioListTile<int>(
title: Text('Option 3'),
value: 3,
groupValue: _selectedValue,
onChanged: (value) {
setState(() {
_selectedValue = value!;
});
},
),
],
), ), ); }}
11. Display Icon:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Display Icon 18-11-2024'),
),
body: Center(
child: Icon(
Icons.star,
size: 50,
color: Colors.yellow,
),
),
),
);
}
}
12. Display Different Types of Buttons:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Different Types of Buttons 25-11-2024'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {},
child: Text('Elevated Button'),
),
TextButton(
onPressed: () {},
child: Text('Text Button'),
),
OutlinedButton(
onPressed: () {},
child: Text('Outlined Button'),
),
IconButton(
icon: Icon(Icons.thumb_up),
onPressed: () {},
),
],
),
),
),
);
}
}
13. Display List of Items Using Menu:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('List of Items Using Menu 02-12-2024'),
),
body: Center(
child: PopupMenuButton<String>(
onSelected: (String result) {
// Handle menu selection
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'Item 1',
child: Text('Item 1'),
),
const PopupMenuItem<String>(
value: 'Item 2',
child: Text('Item 2'),
),
const PopupMenuItem<String>(
value: 'Item 3',
child: Text('Item 3'),
),
],
),
),
),
);
}
}
14. Display Login Screen:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: LoginScreen(),
);
}
}

class LoginScreen extends StatelessWidget {


final TextEditingController _usernameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Login Screen 09-12-2024'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: _usernameController,
decoration: InputDecoration(labelText: 'Username'),
),
TextField(
controller: _passwordController,
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// Handle login logic
},
child: Text('Login'),
),
],
),
),
);
}
}
15. Display Animation:
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: AnimationScreen(),
);
}
}

class AnimationScreen extends StatefulWidget {


@override
_AnimationScreenState createState() => _AnimationScreenState();
}

class _AnimationScreenState extends State<AnimationScreen>


with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;

@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
_animation = CurvedAnimation(parent: _controller, curve: Curves.easeInOut);
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Animation 27-12-2024'),
),
body: Center(
child: FadeTransition(
opacity: _animation,
child: FlutterLogo(size: 100),
),
),
);
}}

You might also like