Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
implemented the collapsable table
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldevgarg committed Feb 1, 2024
1 parent 0e72485 commit 90a9f88
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 160 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:mgramseva/providers/reports_provider.dart';
import 'package:mgramseva/screeens/generate_bill/widgets/WaterConnectionCountWidget.dart';
import 'package:mgramseva/screeens/generate_bill/widgets/water_connection_count_widget.dart';
import 'package:mgramseva/widgets/keyboard_focus_watcher.dart';
import 'package:mgramseva/model/bill/bill_generation_details/bill_generation_details.dart';
import 'package:mgramseva/model/connection/water_connection.dart';
Expand Down

This file was deleted.

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())),
],
);
}
}
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),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Common {
String get LAST_BILL_CYCLE_DEMAND_NOT_GENERATED => 'LAST_BILL_CYCLE_DEMAND_NOT_GENERATED';
String get LAST_BILL_CYCLE_DEMAND_GENERATED => 'LAST_BILL_CYCLE_DEMAND_GENERATED';
String get WS_REPORTS_WATER_CONNECTION_COUNT => 'WS_REPORTS_WATER_CONNECTION_COUNT';
String get COLLAPSE => 'COLLAPSE';
String get NAME => 'CORE_COMMON_NAME';
String get CONTINUE_TO_LOGIN => 'CONTINUE_TO_LOGIN';
String get PHONE_NUMBER => 'CORE_COMMON_PHONE_NUMBER';
Expand Down

0 comments on commit 90a9f88

Please sign in to comment.