This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e72485
commit 90a9f88
Showing
5 changed files
with
222 additions
and
160 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
frontend/mgramseva/lib/screeens/generate_bill/generate_bill.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 0 additions & 159 deletions
159
frontend/mgramseva/lib/screeens/generate_bill/widgets/WaterConnectionCountWidget.dart
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
frontend/mgramseva/lib/screeens/generate_bill/widgets/count_table_widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; | ||
import 'package:mgramseva/utils/constants/i18_key_constants.dart'; | ||
import '../../../utils/date_formats.dart'; | ||
import '../../../utils/localization/application_localizations.dart'; | ||
|
||
class CountTableWidget extends StatefulWidget { | ||
final List<WaterConnectionCount>? waterConnectionCount; | ||
|
||
const CountTableWidget({Key? key, this.waterConnectionCount}) | ||
: super(key: key); | ||
|
||
@override | ||
_CountTableWidgetState createState() => _CountTableWidgetState(); | ||
} | ||
|
||
class _CountTableWidgetState extends State<CountTableWidget> { | ||
bool _isCollapsed = true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final List<WaterConnectionCount>? connectionCount = | ||
widget.waterConnectionCount; | ||
|
||
return Container( | ||
child: Column( | ||
children: [ | ||
LayoutBuilder( | ||
builder: (context, constraints) { | ||
if (constraints.maxWidth <= 760) { | ||
return Container( | ||
width: MediaQuery.of(context).size.width, | ||
child: FittedBox( | ||
child: _buildDataTable(connectionCount!), | ||
), | ||
); | ||
} else { | ||
return Container( | ||
width: MediaQuery.of(context).size.width, | ||
child: _buildDataTable(connectionCount!)); | ||
} | ||
}, | ||
), | ||
if (connectionCount!.length >= 5) | ||
Align( | ||
alignment: Alignment.bottomRight, | ||
child: TextButton( | ||
onPressed: () { | ||
setState(() { | ||
_isCollapsed = !_isCollapsed; | ||
}); | ||
}, | ||
child: Text(_isCollapsed | ||
? "${ApplicationLocalizations.of(context).translate(i18.common.VIEW_ALL)}" | ||
: "${ApplicationLocalizations.of(context).translate(i18.common.COLLAPSE)}"), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Widget _buildDataTable(List<WaterConnectionCount> connectionCount) { | ||
return DataTable( | ||
border: TableBorder.all( | ||
width: 0.5, borderRadius: BorderRadius.all(Radius.circular(5))), | ||
columns: [ | ||
DataColumn( | ||
label: FittedBox( | ||
child: Text( | ||
"${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_MONTH)}"))), | ||
DataColumn( | ||
label: FittedBox( | ||
child: Text( | ||
"${ApplicationLocalizations.of(context).translate(i18.common.CONSUMER_COUNT)}"))) | ||
], | ||
rows: _isCollapsed | ||
? connectionCount.take(5).map((e) => _buildDataRow(e)).toList() | ||
: connectionCount.map((e) => _buildDataRow(e)).toList(), | ||
); | ||
} | ||
|
||
DataRow _buildDataRow(WaterConnectionCount count) { | ||
return DataRow( | ||
cells: [ | ||
DataCell(Text(DateFormats.getMonthAndYearFromDateTime( | ||
DateTime.fromMillisecondsSinceEpoch(count.taxperiodto!)))), | ||
DataCell(Text(count.count.toString())), | ||
], | ||
); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
frontend/mgramseva/lib/screeens/generate_bill/widgets/water_connection_count_widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mgramseva/model/reports/WaterConnectionCount.dart'; | ||
import 'package:mgramseva/providers/reports_provider.dart'; | ||
import 'package:mgramseva/utils/constants/i18_key_constants.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import '../../../utils/localization/application_localizations.dart'; | ||
import '../../../widgets/label_text.dart'; | ||
import 'count_table_widget.dart'; | ||
|
||
class WaterConnectionCountWidget extends StatefulWidget { | ||
@override | ||
_WaterConnectionCountWidgetState createState() => | ||
_WaterConnectionCountWidgetState(); | ||
} | ||
|
||
class _WaterConnectionCountWidgetState | ||
extends State<WaterConnectionCountWidget> { | ||
@override | ||
void initState() { | ||
WidgetsBinding.instance.addPostFrameCallback((_) => afterViewBuild()); | ||
super.initState(); | ||
} | ||
|
||
afterViewBuild() { | ||
Provider.of<ReportsProvider>(context, listen: false) | ||
..getWaterConnectionsCount(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
width: MediaQuery.of(context).size.width, | ||
child: Card( | ||
child: Padding( | ||
padding: const EdgeInsets.only(bottom: 20.0), | ||
child: Container( | ||
child: Column( | ||
children: [ | ||
LabelText( | ||
'${"${ApplicationLocalizations.of(context).translate(i18.common.WS_REPORTS_WATER_CONNECTION_COUNT)}"}'), | ||
Container( | ||
margin: MediaQuery.of(context).size.width > 760 | ||
? EdgeInsets.only(top: 5.0, bottom: 5, right: 20, left: 20) | ||
: EdgeInsets.only(top: 5.0, bottom: 5, right: 8, left: 8), | ||
child: LayoutBuilder( | ||
builder: (context, constraints) { | ||
final provider = Provider.of<ReportsProvider>(context); | ||
final waterConnectionCount = provider.waterConnectionCount; | ||
if (waterConnectionCount == null) { | ||
return SizedBox(); | ||
} | ||
return Column( | ||
children: [ | ||
if (constraints.maxWidth > 760) | ||
_buildDataTableRow( | ||
context, | ||
"${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", | ||
waterConnectionCount | ||
.waterConnectionsDemandGenerated, | ||
), | ||
if (constraints.maxWidth <= 760) | ||
_buildDataTableColumn( | ||
context, | ||
"${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_GENERATED)}", | ||
waterConnectionCount | ||
.waterConnectionsDemandGenerated, | ||
), | ||
SizedBox(height: 20), | ||
if (constraints.maxWidth > 760) | ||
_buildDataTableRow( | ||
context, | ||
"${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", | ||
waterConnectionCount | ||
.waterConnectionsDemandNotGenerated, | ||
), | ||
if (constraints.maxWidth <= 760) | ||
_buildDataTableColumn( | ||
context, | ||
"${ApplicationLocalizations.of(context).translate(i18.common.LAST_BILL_CYCLE_DEMAND_NOT_GENERATED)}", | ||
waterConnectionCount | ||
.waterConnectionsDemandNotGenerated, | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _buildDataTableRow(BuildContext context, String title, | ||
List<WaterConnectionCount>? waterConnections) { | ||
return Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Container( | ||
alignment: Alignment.centerLeft, | ||
width: MediaQuery.of(context).size.width / 3, | ||
padding: EdgeInsets.only(top: 18, bottom: 3), | ||
child: Text(title), | ||
), | ||
Container( | ||
width: MediaQuery.of(context).size.width / 2.5, | ||
padding: EdgeInsets.only(top: 18, bottom: 3), | ||
child: CountTableWidget(waterConnectionCount: waterConnections), | ||
), | ||
], | ||
); | ||
} | ||
|
||
Widget _buildDataTableColumn(BuildContext context, String title, | ||
List<WaterConnectionCount>? waterConnections) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text(title), | ||
SizedBox(height: 10), | ||
CountTableWidget(waterConnectionCount: waterConnections), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters