import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
home: AppHeader(),
debugShowCheckedModeBanner: false,
));
}
class AppHeader extends StatefulWidget {
const AppHeader({super.key});
@override
State<AppHeader> createState() => _AppHeaderState();
}
class _AppHeaderState extends State<AppHeader> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blueAccent,
title: const Align(
alignment: Alignment.centerLeft,
child: Text(
"Tip Calculator",
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.w600,
),
),
),
),
body: const AppBody(),
);
}
}
class AppBody extends StatefulWidget {
const AppBody({super.key});
@override
State<AppBody> createState() => _AppBodyState();
}
class _AppBodyState extends State<AppBody> {
int _tipPercentage = 0;
double _billAmount = 0;
int _noOfPerson = 1;
double _serviceCharge = 0.0;
@override
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(
height: 20.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 220,
width: 450,
decoration: BoxDecoration(
color: Colors.blue[400],
borderRadius: BorderRadius.circular(
20.0,
),
),
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Payble Bill Amount",
style: TextStyle(
color: Colors.white,
fontSize: 17.0,
fontWeight: FontWeight.w600,
),
),
Text(
"2560.00",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.w100,
),
),
],
),
),
],
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(15.0),
height: 220,
width: 450,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
gradient: LinearGradient(
colors: [Colors.blue.shade50, Colors.blue.shade100],
begin: Alignment.topRight,
end: Alignment.bottomRight,
),
border: Border.all(
color: Colors.blue.shade200,
width: 3,
),
),
child: Column(
children: [
TextField(
decoration: InputDecoration(
prefixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.monetization_on_rounded,
color: Colors.blue,
),
SizedBox(width: 5.0),
Text(
"Bill Amount: ",
style: TextStyle(
color: Colors.blue,
fontSize: 20.0,
fontWeight: FontWeight.w600,
),
),
],
),
border: InputBorder.none,
),
onChanged: (String value) {
try {
_billAmount = double.parse(value);
}
catch (exception) {
_billAmount = 0.0;
}
},
),
Row(
children: [
const Text(
"Number of Person: ",
style: TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
const SizedBox(
width: 30,
),
InkWell(
onTap: () {
setState(() {
if (_noOfPerson > 1) {
_noOfPerson--;
}
});
},
child: Container(
width: 30,
height: 30,
color: Colors.blueAccent,
child: const Icon(
Icons.remove,
color: Colors.white,
),
),
),
const SizedBox(
width: 20,
),
Text(
"$_noOfPerson",
style: TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
const SizedBox(
width: 20,
),
InkWell(
onTap: () {
setState(() {
_noOfPerson++;
});
},
child: Container(
width: 30,
height: 30,
color: Colors.blueAccent,
child: const Icon(
Icons.add,
color: Colors.white,
),
),
),
],
),
const SizedBox(
height: 20.0,
),
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Service charges: ",
style: TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
Text(
"20.00",
style: TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
],
),
Expanded(
child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
"Tip(s): ",
style: TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
Text(
"$_tipPercentage%",
style: const TextStyle(
fontSize: 15.5, fontWeight: FontWeight.w600),
),
Slider(
value: _tipPercentage.toDouble(),
min: 0,
max: 100,
divisions: 10,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
label: "$_tipPercentage",
onChanged: (double newVal) {
setState(() {
_tipPercentage = newVal.toInt();
});
}),
],
),
),
],
),
),
],
),
const SizedBox(
height: 10,
),
],
);
}
calculateServiceCharge(int person, double bill, int precentage) {
if (bill <= 0) {
return 0.0;
}
else {
_serviceCharge = bill * (precentage / 100);
return _serviceCharge;
}
}
}
And what is the message?