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

File 3

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

File 3

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: BillSplitterApp(),
);
}
}

class BillSplitterApp extends StatefulWidget {


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

class _BillSplitterAppState extends State<BillSplitterApp> {


final TextEditingController billAmountController = TextEditingController();
final TextEditingController peopleCountController = TextEditingController();
String splitAmountMessage = "";

void calculateSplitAmount() {
setState(() {
double? totalBill = double.tryParse(billAmountController.text);
int? numberOfPeople = int.tryParse(peopleCountController.text);

if (totalBill == null || numberOfPeople == null || numberOfPeople <= 0) {


splitAmountMessage = "Please enter a valid bill amount and number of
people.";
} else {
double splitAmount = totalBill / numberOfPeople;
splitAmountMessage = "Each person should pay: \$$
{splitAmount.toStringAsFixed(2)}";
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Bill Splitter'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: billAmountController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter total bill amount',
border: OutlineInputBorder(),
),
),
SizedBox(height: 16),
TextField(
controller: peopleCountController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter number of people',
border: OutlineInputBorder(),
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: calculateSplitAmount,
child: Text('Calculate Split Amount'),
),
SizedBox(height: 16),
Text(
splitAmountMessage,
style: TextStyle(fontSize: 18),
),
],
),
),
);
}
}

You might also like