0% found this document useful (0 votes)
8 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)
8 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
You are on page 1/ 2

week-6

write a program to create custom widgets for specific UI elements

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('Custom Widget Example'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: CustomTextField(
hintText: 'Enter your name',
onChanged: (value) {
print('Name changed: $value');
},
),
),
SizedBox(height: 20),
Padding(
padding: const EdgeInsets.all(8.0),
child: CustomTextField(
hintText: 'Enter Email',
onChanged: (value) {
print('Name changed: $value');
},
),
),
SizedBox(height: 20),
Padding(
padding: const EdgeInsets.all(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 this.text,
@required this.onPressed,
}) : 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 this.hintText,
required this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextField(
onChanged: onChanged,
decoration: InputDecoration(
hintText: hintText,
border: OutlineInputBorder(),
),
);
}
}

You might also like