merge dev to devices view

This commit is contained in:
ashrafzarkanisala
2024-08-24 14:21:10 +03:00
32 changed files with 1822 additions and 1095 deletions

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
class DynamicTable extends StatefulWidget {
final List<String> headers;
@ -8,20 +10,24 @@ class DynamicTable extends StatefulWidget {
final BoxDecoration? cellDecoration;
final Size size;
final bool withCheckBox;
final bool isEmpty;
final void Function(bool?)? selectAll;
final void Function(int, bool?)? onRowCheckboxChanged;
final List<String>? initialSelectedIds;
const DynamicTable({
Key? key,
super.key,
required this.headers,
required this.data,
required this.size,
required this.isEmpty,
required this.withCheckBox,
this.headerDecoration,
this.cellDecoration,
this.selectAll,
this.onRowCheckboxChanged,
}) : super(key: key);
this.initialSelectedIds,
});
@override
_DynamicTableState createState() => _DynamicTableState();
@ -34,7 +40,11 @@ class _DynamicTableState extends State<DynamicTable> {
@override
void initState() {
super.initState();
_selected = List<bool>.filled(widget.data.length, false);
_selected = List<bool>.generate(widget.data.length, (index) {
return widget.initialSelectedIds != null &&
widget.initialSelectedIds!.contains(widget.data[index][1]);
});
_selectAll = _selected.every((element) => element == true);
}
void _toggleSelectAll(bool? value) {
@ -62,7 +72,7 @@ class _DynamicTableState extends State<DynamicTable> {
return Container(
decoration: widget.cellDecoration,
child: Padding(
padding: const EdgeInsets.all(10.0),
padding: const EdgeInsets.all(2.0),
child: ListView(
scrollDirection: Axis.horizontal,
children: [
@ -82,27 +92,60 @@ class _DynamicTableState extends State<DynamicTable> {
],
),
),
Expanded(
child: Container(
color: Colors.white,
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.data.length,
itemBuilder: (context, index) {
final row = widget.data[index];
return Row(
widget.isEmpty
? Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (widget.withCheckBox) _buildRowCheckbox(index),
...row
.map((cell) =>
_buildTableCell(cell.toString()))
.toList(),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
SvgPicture.asset(Assets.emptyTable),
const SizedBox(
height: 15,
),
Text(
'No Passwords',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor),
)
],
),
],
),
],
);
},
),
),
),
),
)
: Expanded(
child: Container(
color: Colors.white,
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.data.length,
itemBuilder: (context, index) {
final row = widget.data[index];
return Row(
children: [
if (widget.withCheckBox)
_buildRowCheckbox(
index, widget.size.height * 0.10),
...row
.map((cell) => _buildTableCell(
cell.toString(),
widget.size.height * 0.10))
.toList(),
],
);
},
),
),
),
],
),
),
@ -113,8 +156,11 @@ class _DynamicTableState extends State<DynamicTable> {
}
Widget _buildSelectAllCheckbox() {
return SizedBox(
width: 50,
return Container(
padding: const EdgeInsets.all(8.0),
decoration: const BoxDecoration(
border: Border.symmetric(
vertical: BorderSide(color: ColorsManager.boxDivider))),
child: Checkbox(
value: _selectAll,
onChanged: _toggleSelectAll,
@ -122,16 +168,26 @@ class _DynamicTableState extends State<DynamicTable> {
);
}
Widget _buildRowCheckbox(int index) {
return SizedBox(
width: 50,
child: Checkbox(
value: _selected[index],
onChanged: (bool? value) {
_toggleRowSelection(index, value);
},
),
);
Widget _buildRowCheckbox(int index, size) {
return Container(
padding: const EdgeInsets.all(8.0),
height: size,
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: ColorsManager.boxDivider,
width: 1.0,
),
)),
alignment: Alignment.centerLeft,
child: Center(
child: Checkbox(
value: _selected[index],
onChanged: (bool? value) {
_toggleRowSelection(index, value);
},
),
));
}
Widget _buildTableHeaderCell(String title) {
@ -146,17 +202,18 @@ class _DynamicTableState extends State<DynamicTable> {
child: Text(title,
style: const TextStyle(
fontWeight: FontWeight.w400,
color: ColorsManager.lightGreyColor)),
fontSize: 13,
color: Color(0xFF999999))),
),
),
);
}
Widget _buildTableCell(String content) {
Widget _buildTableCell(String content, size) {
return Expanded(
child: Container(
height: 80,
padding: const EdgeInsets.all(15.0),
height: size,
padding: const EdgeInsets.all(5.0),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
@ -167,7 +224,8 @@ class _DynamicTableState extends State<DynamicTable> {
alignment: Alignment.centerLeft,
child: Text(
content,
style: const TextStyle(color: Colors.black, fontSize: 12),
style: const TextStyle(
color: Colors.black, fontSize: 10, fontWeight: FontWeight.w400),
),
),
);