Skip to content

Commit

Permalink
💄 chore: update table contents
Browse files Browse the repository at this point in the history
  • Loading branch information
fleeser committed May 23, 2024
1 parent 42fe956 commit 2c50860
Show file tree
Hide file tree
Showing 53 changed files with 685 additions and 447 deletions.
42 changes: 42 additions & 0 deletions flutter/lib/core/common/widgets/hb_chip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';

import 'package:habib_app/core/res/theme/spacing/hb_spacing.dart';
import 'package:habib_app/core/res/theme/typography/hb_typography.dart';

class HBChip extends StatelessWidget {

final String text;
final Color color;

const HBChip({
super.key,
required this.text,
required this.color
});

@override
Widget build(BuildContext context) {
return Container(
height: 30.0,
padding: const EdgeInsets.symmetric(horizontal: HBSpacing.md),
alignment: Alignment.center,
decoration: BoxDecoration(
color: color.withOpacity(0.4),
borderRadius: BorderRadius.circular(15.0),
border: Border.all(
width: 1.5,
color: color
)
),
child: Text(
text,
textAlign: TextAlign.center,
style: HBTypography.base.copyWith(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: color
)
)
);
}
}
76 changes: 56 additions & 20 deletions flutter/lib/core/common/widgets/hb_table.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import 'package:flutter_conditional/flutter_conditional.dart';
import 'package:habib_app/core/common/widgets/hb_chip.dart';

import 'package:habib_app/core/res/theme/colors/hb_colors.dart';
import 'package:habib_app/core/res/theme/spacing/hb_spacing.dart';
Expand All @@ -22,7 +23,7 @@ class HBTable extends StatelessWidget {
final int columnLength;
final List<double> fractions;
final List<String> titles;
final List<List<String>> items;
final List<List<HBTableItem>> items;
final String? text;
final void Function(int index)? onPressed;

Expand Down Expand Up @@ -82,10 +83,15 @@ class HBTable extends StatelessWidget {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(HBUIConstants.defaultBorderRadius)),
child: Row(
children: List.generate(columnLength, (int columnIndex) {
return HBTableText(
width: tableWidth * fractions[columnIndex],
text: items[rowIndex][columnIndex]
);
final HBTableItem item = items[rowIndex][columnIndex];

return switch (item.type) {
HBTableItemType.text => SizedBox(
width: tableWidth * fractions[columnIndex],
child: item
),
HBTableItemType.chip => item
};
})
)
)
Expand Down Expand Up @@ -144,31 +150,61 @@ class HBTableTitle extends StatelessWidget {
}
}

class HBTableText extends StatelessWidget {
enum HBTableItemType {
text,
chip
}

class HBTableItem extends StatelessWidget {

final HBTableItemType type;

const HBTableItem({
super.key,
required this.type
});

@override
Widget build(BuildContext context) {
throw UnimplementedError();
}
}

class HBTableText extends HBTableItem {

final double width;
final String text;

const HBTableText({
super.key,
required this.width,
required this.text
});
}) : super(type: HBTableItemType.text);

@override
Widget build(BuildContext context) {
return SizedBox(
width: width,
child: Text(
text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: HBTypography.base.copyWith(
fontSize: 14.0,
fontWeight: FontWeight.w400,
color: HBColors.gray900
)
return Text(
text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: HBTypography.base.copyWith(
fontSize: 14.0,
fontWeight: FontWeight.w400,
color: HBColors.gray900
)
);
}
}

class HBTableChip extends HBTableItem {

final HBChip chip;

const HBTableChip({
super.key,
required this.chip
}) : super(type: HBTableItemType.chip);

@override
Widget build(BuildContext context) {
return chip;
}
}
5 changes: 4 additions & 1 deletion flutter/lib/core/common/widgets/sc_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HBTextField extends StatelessWidget {
final bool obscure;
final bool isEnabled;
final double? maxWidth;
final void Function(String)? onChanged;

const HBTextField({
super.key,
Expand All @@ -26,7 +27,8 @@ class HBTextField extends StatelessWidget {
this.hint,
this.obscure = false,
this.isEnabled = true,
this.maxWidth
this.maxWidth,
this.onChanged
});

@override
Expand All @@ -35,6 +37,7 @@ class HBTextField extends StatelessWidget {
constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity),
child: TextField(
controller: controller,
onChanged: onChanged,
autocorrect: false,
enabled: isEnabled,
keyboardType: inputType,
Expand Down
6 changes: 6 additions & 0 deletions flutter/lib/core/extensions/datetime_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extension DateTimeExtension on DateTime {

String toHumanReadable() {
return '${ day.toString().padLeft(2, '0') }.${ month.toString().padLeft(2, '0') }.${ year.toString().padLeft(4, '0') }';
}
}
14 changes: 14 additions & 0 deletions flutter/lib/core/extensions/json_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:habib_app/core/utils/typedefs.dart';

extension JsonExtension on Json {

Json jsonFromKeys(List<String> keys) {
Json json = <String, dynamic>{};

for (String key in keys) {
json[key] = this[key];
}

return json;
}
}
Loading

0 comments on commit 2c50860

Please sign in to comment.