0% found this document useful (0 votes)
12 views2 pages

Flutter Week 6

This document contains a Flutter program that demonstrates the creation of custom widgets for UI elements. It includes a main application with a custom text field and button, allowing users to input their name, email, and roll number. The program utilizes StatelessWidgets to define the custom button and text field functionalities.

Uploaded by

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

Flutter Week 6

This document contains a Flutter program that demonstrates the creation of custom widgets for UI elements. It includes a main application with a custom text field and button, allowing users to input their name, email, and roll number. The program utilizes StatelessWidgets to define the custom button and text field functionalities.

Uploaded by

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

week-6

write a program to create custom widgets for specific UI elements

import 'package:flutter/[Link]';

void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Custom Widget Example'),
),
body: Column(
mainAxisAlignment: [Link],
children: <Widget>[
Padding(
padding: const [Link](8.0),
child: CustomTextField(
hintText: 'Enter your name',
onChanged: (value) {
print('Name changed: $value');
},
),
),
SizedBox(height: 20),
Padding(
padding: const [Link](8.0),
child: CustomTextField(
hintText: 'Enter Email',
onChanged: (value) {
print('Name changed: $value');
},
),
),
SizedBox(height: 20),
Padding(
padding: const [Link](8.0),
child: CustomTextField(
hintText: 'Enter Roll Number',
onChanged: (value) {
print('Name changed: $value');
},
),
),
SizedBox(height: 20),
CustomButton(
text: 'Press Me',
onPressed: () {
print('Button pressed!');
},
),
],
),
),
);
}
}
class CustomButton extends StatelessWidget {
final String? text;
final VoidCallback? onPressed;
const CustomButton({
Key? key,
@required [Link],
@required [Link],
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
child: Text(text!),
);
}
}
class CustomTextField extends StatelessWidget {
final String hintText;
final ValueChanged<String> onChanged;
const CustomTextField({
Key? key,
required [Link],
required [Link],
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextField(
onChanged: onChanged,
decoration: InputDecoration(
hintText: hintText,
border: OutlineInputBorder(),
),
);
}
}

You might also like