Untitled
unknown
plain_text
8 months ago
20 kB
4
Indexable
import 'package:flutter/material.dart';
import 'dashboard_page.dart.';
class DataEntryPage extends StatefulWidget {
@override
_DataEntryPageState createState() => _DataEntryPageState();
}
class _DataEntryPageState extends State<DataEntryPage> {
// Place the MF Map here (inside the class but before any methods)
Map<String, double> calculatedValues = {}; // Store calculated values
Map<String, String> calculatedResults = {};
final Map<String, double> commonParamMFs = {
"66KV": 1.732,
"11KV": 1.732,
"66KV PF": 1.0,
"11KV PF": 1.0,
"Frequency": 1.0,
};
// Store controllers for each input field
Map<String, TextEditingController> controllers = {};
void _calculateAndUpdate(String param) {
double inputValue = double.tryParse(controllers[param]!.text) ?? 0.0;
double calculatedValue = inputValue * (commonParamMFs[param] ?? 1.0);
setState(() {
calculatedValues[param] = calculatedValue; // Store result separately
});
print("Input for $param: $inputValue");
print("Calculated Value: $calculatedValue");
}
@override
void initState() {
super.initState();
// Initialize controllers for each common parameter
for (var param in commonParamMFs.keys) {
controllers[param] = TextEditingController();
}
}
bool isSaved = false;
int _selectedIndex = 1;
DateTime _currentDateTime = DateTime.now(); // Current date and time
void _onItemTapped(int index) {
if (index != _selectedIndex) {
late Widget nextPage;
switch (index) {
case 0:
nextPage = DashboardPage();
break;
case 1:
nextPage = DataEntryPage(); // This needs to refer to the actual DataEntryPage class
break;
default:
return; // Exit if index is not 0 or 1
}
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => nextPage),
);
}
}
// Function to round the time to the nearest hour
String getRoundedTime() {
DateTime roundedTime = DateTime(
_currentDateTime.year,
_currentDateTime.month,
_currentDateTime.day,
_currentDateTime.hour, // The hour value is kept, minute is discarded
);
return "${roundedTime.hour.toString().padLeft(2, '0')}:00"; // Format time as "HH:00"
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"SubTrack Data Entry",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
fontFamily: 'Rajdhani',
color: Colors.white,
),
),
backgroundColor: Color(0xFF282833),
),
//Bottomnavbar building
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Color(0xFF282833),
selectedItemColor: Color(0xFFF3B600),
unselectedItemColor: Colors.white.withOpacity(0.7),
selectedLabelStyle: TextStyle(
fontSize: 14,
fontFamily: 'Rajdhani',
fontWeight: FontWeight.bold,
),
unselectedLabelStyle: TextStyle(
fontSize: 12,
fontFamily: 'Rajdhani',
fontWeight: FontWeight.bold,
),
currentIndex: _selectedIndex,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
BottomNavigationBarItem(icon: Icon(Icons.edit), label: "Data Entry"),
BottomNavigationBarItem(icon: Icon(Icons.calculate), label: "Losses"),
BottomNavigationBarItem(icon: Icon(Icons.history), label: "History"),
],
),
backgroundColor: Color(0xFF282833),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Displaying Date on the Left and Time on the Right
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"${_currentDateTime.toLocal()}".split(' ')[0], // Displaying only the date
style: TextStyle(color: Colors.blue, fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
"Time: [ ${getRoundedTime()} ]",
style: TextStyle(color: Colors.blue, fontSize: 18, fontWeight: FontWeight.bold),
),
],
),
SizedBox(height: 20),
_buildCommonParameters(),
_build66KVLinesSection(),
_buildAllOtherPanelsSection(),
_buildLTMeterAnd11KVStation(),
SizedBox(height: 20),
// Row with Save and Modify Buttons
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
setState(() {
isSaved = true;
});
},
child: Text(
"Save Data",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green, // Button background color
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
elevation: 5,
),
),
SizedBox(width: 20),
if (isSaved)
ElevatedButton(
onPressed: () {},
child: Text(
"Modify",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 30),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
elevation: 5,
),
),
],
),
],
),
),
),
);
}
//common parameters building (independent)
Widget _buildCommonParameters() {
List<String> commonParams = ["66KV", "11KV", "66KV PF", "11KV PF", "Frequency"];
Map<String, double> mfValues = { // Define multiplication factors
"66KV": 1.732,
"11KV": 1.732,
"66KV PF": 1.0,
"11KV PF": 1.0,
"Frequency": 1.0,
};
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Common Parameters",
style: TextStyle(
color: Color(0xFFF3B600),
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Column(
children: commonParams.map((param) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(
param,
style: TextStyle(
color: Colors.redAccent,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
flex: 2,
child: _buildInputBox(param, mfValues[param]!),
),
],
),
);
}).toList(),
),
SizedBox(height: 20),
],
);
}
// 🔥 New Input Box Function with Overlay Calculation
Widget _buildInputBox(String param, double mf) {
TextEditingController controller = TextEditingController();
return Stack(
children: [
TextField(
controller: controller,
keyboardType: TextInputType.number,
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
decoration: InputDecoration(
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
onChanged: (value) {
double input = double.tryParse(value) ?? 0.0;
setState(() {
calculatedResults[param] = (input * mf).toStringAsFixed(2);
});
},
),
if (calculatedResults[param] != null && controller.text.isEmpty)
Positioned(
top: 8,
left: 8,
child: Text(
calculatedResults[param]!,
style: TextStyle(
color: Colors.blueAccent,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
);
}
//66KV Lines Section (Independent Design)
Widget _build66KVLinesSection() {
List<String> fields = [
"66KV Ranavav-1", "66KV Ranavav-2", "66KV Bagvadar",
"66KV Degam-1", "66KV Degam-2"
];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"66KV Lines (Amp, Import & Export MWh)",
style: TextStyle(
color: Color(0xFFF3B600),
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Column(
children: fields.map((field) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(
field,
style: TextStyle(
color: Colors.redAccent,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
width: 70,
height: 40,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 22, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 6.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
SizedBox(width: 10),
SizedBox(
width: 100,
height: 40,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 20, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
SizedBox(width: 10),
SizedBox(
width: 100,
height: 40,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 20, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
],
),
);
}).toList(),
),
SizedBox(height: 10),
],
);
}
//All Other Panels Section (Independent Design)
Widget _buildAllOtherPanelsSection() {
List<String> panels = [
"66KV TR-1", "66KV TR-2", "11KV Incomer-1", "11KV Incomer-2",
"11KV Kharva", "11KV Katvana", "11KV Pav", "11KV Bildi", "11KV Timbi"
];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"All Other Panels (Amp & MWh)",
style: TextStyle(
color: Color(0xFFF3B600),
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Column(
children: panels.map((panel) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(
panel,
style: TextStyle(
color: Colors.redAccent,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
width: 80,
height: 40,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 24, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
SizedBox(width: 10),
SizedBox(
width: 120,
height: 40,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 22, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
],
),
);
}).toList(),
),
SizedBox(height: 10),
],
);
}
//LT Meter & 11KV Station Section (Independent Design)
Widget _buildLTMeterAnd11KVStation() {
List<String> panels = ["LT Meter", "11KV Station"];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"LT Meter & 11KV Station (MWh Only)",
style: TextStyle(
color: Color(0xFFF3B600),
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Column(
children: panels.map((panel) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Expanded(
flex: 2,
child: Text(
panel,
style: TextStyle(
color: Colors.redAccent,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
width: 210, // Custom width for MWh input in this section
height: 55,
child: TextField(
style: TextStyle(
color: Colors.black, // Change text color here
fontSize: 28, // Set your desired font size
fontWeight: FontWeight.bold, // Set your desired font weight
),
textAlign: TextAlign.center, // Align text to the center
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), // Adjust vertical padding
fillColor: Colors.yellowAccent,
filled: true,
border: OutlineInputBorder(),
),
),
),
],
),
);
}).toList(),
),
SizedBox(height: 10),
],
);
}
}Editor is loading...
Leave a Comment