Skip to content

Commit

Permalink
Merge pull request #295 from Securrency-OSS/dv/mirai-table
Browse files Browse the repository at this point in the history
feat: Add Mirai Table Parser
  • Loading branch information
divyanshub024 authored May 4, 2024
2 parents 2a418da + 3ce46ec commit 9cb7645
Show file tree
Hide file tree
Showing 13 changed files with 3,095 additions and 1,231 deletions.
2,494 changes: 1,264 additions & 1,230 deletions examples/mirai_gallery/assets/json/home_screen.json

Large diffs are not rendered by default.

221 changes: 221 additions & 0 deletions examples/mirai_gallery/assets/json/table_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"type": "scaffold",
"appBar": {
"type": "appBar",
"title": {
"type": "text",
"data": "Mirai Table Example"
}
},
"body": {
"type": "padding",
"padding": 16.0,
"child": {
"type": "table",
"defaultColumnWidth": {
"type": "flexColumnWidth",
"value": 1
},
"border": {
"type": "tableBorder",
"borderSide": {
"color": "#000000",
"width": 1.0
}
},
"children": [
{
"type": "tableRow",
"children": [
{
"type": "tableCell",
"child": {
"type": "container",
"color": "#40000000",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Header 1"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "container",
"color": "#40000000",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Header 2"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "container",
"color": "#40000000",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Header 3"
}
}
}
}
]
},
{
"type": "tableRow",
"children": [
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 1, Cell 1"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 1, Cell 2"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 1, Cell 3"
}
}
}
}
]
},
{
"type": "tableRow",
"children": [
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 2, Cell 1"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 2, Cell 2"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 2, Cell 3"
}
}
}
}
]
},
{
"type": "tableRow",
"children": [
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 3, Cell 1"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 3, Cell 2"
}
}
}
},
{
"type": "tableCell",
"child": {
"type": "sizedBox",
"height": 50.0,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "Row 3, Cell 3"
}
}
}
}
]
}
]
}
}
}
3 changes: 2 additions & 1 deletion packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
import 'package:mirai/src/action_parsers/action_parsers.dart';
import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart';
import 'package:mirai/src/framework/mirai_registry.dart';
import 'package:mirai/src/parsers/mirai_auto_complete/mirai_auto_complete_parser.dart';
import 'package:mirai/src/parsers/parsers.dart';
import 'package:mirai/src/services/mirai_network_service.dart';
import 'package:mirai/src/utils/log.dart';
Expand Down Expand Up @@ -71,6 +70,8 @@ class Mirai {
const MiraiDefaultBottomNavigationControllerParser(),
const MiraiWrapParser(),
const MiraiAutoCompleteParser(),
const MiraiTableParser(),
const MiraiTableCellParser(),
];

static final _actionParsers = <MiraiActionParser>[
Expand Down
71 changes: 71 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_table/mirai_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mirai/mirai.dart';

export 'package:mirai/src/parsers/mirai_table/mirai_table_parser.dart';

part 'mirai_table.freezed.dart';
part 'mirai_table.g.dart';

enum MiraiTableColumnWidthType {
fixedColumnWidth,
flexColumnWidth,
fractionColumnWidth,
intrinsicColumnWidth
}

@freezed
class MiraiTable with _$MiraiTable {
const factory MiraiTable({
@Default([]) List<MiraiTableRow> children,
Map<int, MiraiTableColumnWidth>? columnWidths,
MiraiTableColumnWidth? defaultColumnWidth,
TextDirection? textDirection,
MiraiTableBorder? border,
@Default(TableCellVerticalAlignment.top)
TableCellVerticalAlignment defaultVerticalAlignment,
TextBaseline? textBaseline,
}) = _MiraiTable;

factory MiraiTable.fromJson(Map<String, dynamic> json) =>
_$MiraiTableFromJson(json);
}

@freezed
class MiraiTableRow with _$MiraiTableRow {
const factory MiraiTableRow({
MiraiBoxDecoration? decoration,
@Default([]) List<Map<String, dynamic>> children,
}) = _MiraiTableRow;

factory MiraiTableRow.fromJson(Map<String, dynamic> json) =>
_$MiraiTableRowFromJson(json);
}

@freezed
class MiraiTableBorder with _$MiraiTableBorder {
const factory MiraiTableBorder({
MiraiBorderSide? top,
MiraiBorderSide? right,
MiraiBorderSide? bottom,
MiraiBorderSide? left,
MiraiBorderSide? horizontalInside,
MiraiBorderSide? verticalInside,
MiraiBorderRadius? borderRadius,
}) = _MiraiTableBorder;

factory MiraiTableBorder.fromJson(Map<String, dynamic> json) =>
_$MiraiTableBorderFromJson(json);
}

@freezed
class MiraiTableColumnWidth with _$MiraiTableColumnWidth {
const factory MiraiTableColumnWidth({
@Default(MiraiTableColumnWidthType.flexColumnWidth)
MiraiTableColumnWidthType type,
double? value,
}) = _MiraiTableColumnWidth;

factory MiraiTableColumnWidth.fromJson(Map<String, dynamic> json) =>
_$MiraiTableColumnWidthFromJson(json);
}
Loading

0 comments on commit 9cb7645

Please sign in to comment.