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

File 2

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)
4 views2 pages

File 2

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

void main() {

runApp(MyApp());
}

class MyApp extends StatelessWidget {


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

class NumberCheckApp extends StatefulWidget {


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

class _NumberCheckAppState extends State<NumberCheckApp> {


final TextEditingController numberController = TextEditingController();
String resultMessage = "";

void checkEvenOdd() {
setState(() {
int? number = int.tryParse(numberController.text);
if (number == null) {
resultMessage = "Please enter a valid number.";
} else if (number % 2 == 0) {
resultMessage = "The number $number is Even.";
} else {
resultMessage = "The number $number is Odd.";
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Even or Odd Checker'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: numberController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter a number',
border: OutlineInputBorder(),
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: checkEvenOdd,
child: Text('Check Even or Odd'),
),
SizedBox(height: 16),
Text(
resultMessage,
style: TextStyle(fontSize: 18),
),
],
),
),
);
}
}

You might also like