Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WIP: Add Support for Drawer Widget #184

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions examples/mirai_gallery/assets/json/drawer_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"type": "scaffold",
"appBar": {
"type": "appBar",
"title": {
"type": "text",
"data": "Appbar"
}
},
"drawer": {
"type": "drawer",
"child": {
"type": "listView",
"shrinkWrap": true,
"separator": {
"type": "container",
"height": 10
},
"children": [
{
"type": "listTile",
"leading": {
"type": "container",
"height": 50,
"width": 50,
"color": "#165FC7",
"child": {
"type": "column",
"mainAxisAlignment": "center",
"crossAxisAlignment": "center",
"children": [
{
"type": "text",
"data": "1",
"style": {
"fontSize": 21,
"color": "#FFFFFF"
}
}
]
}
},
"title": {
"type": "padding",
"padding": {
"top": 10
},
"child": {
"type": "text",
"data": "Item 1",
"style": {
"fontSize": 18
}
}
},
"subtitle": {
"type": "padding",
"padding": {
"top": 10
},
"child": {
"type": "text",
"data": "Item description",
"style": {
"fontSize": 14
}
}
},
"trailing": {
"type": "icon",
"iconType": "material",
"icon": "more_vert",
"size": 24
}
},
{
"type": "listTile",
"onPressed": {
"actionType": "navigate",
"navigationStyle": "pop"
},
"leading": {
"type": "container",
"height": 50,
"width": 50,
"color": "#165FC7",
"child": {
"type": "column",
"mainAxisAlignment": "center",
"crossAxisAlignment": "center",
"children": [
{
"type": "text",
"data": "2",
"style": {
"fontSize": 21,
"color": "#FFFFFF"
}
}
]
}
},
"title": {
"type": "padding",
"padding": {
"top": 10
},
"child": {
"type": "text",
"data": "Item 2",
"style": {
"fontSize": 18
}
}
},
"subtitle": {
"type": "padding",
"padding": {
"top": 10
},
"child": {
"type": "text",
"data": "Item description",
"style": {
"fontSize": 14
}
}
},
"trailing": {
"type": "icon",
"iconType": "material",
"icon": "more_vert",
"size": 24
}
}
]
}
},
"body": {
"type": "center",
"child": {
"type": "elevatedButton",
"child": {
"type": "text",
"data": "Open Drawer"
},
"style": {
"padding": {
"top": 8,
"left": 12,
"right": 12,
"bottom": 8
}
},
"onPressed": {
"actionType": "openDrawer"
}
}
}
}
34 changes: 31 additions & 3 deletions examples/mirai_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
@@ -1588,8 +1588,6 @@
}
}
},


{
"type": "listTile",
"leading": {
@@ -1695,7 +1693,38 @@
}
}
},
{
"type": "listTile",
"leading": {
"type": "icon",
"iconType": "material",
"icon": "navigation"
},

"title": {
"type": "text",
"data": "Mirai Drawer",
"style": {
"fontSize": 21
}
},
"subtitle": {
"type": "text",
"data": "A Material Design Mirai Drawer widget",
"style": {
"fontSize": 12
}
},
"isThreeLine": true,
"onTap": {
"actionType": "navigate",
"navigationStyle": "push",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/drawer_example.json"
}
}
},
{
"type": "listTile",
"leading": {
@@ -1728,7 +1757,6 @@
}
}
},


{
"type": "sizedBox",
1 change: 1 addition & 0 deletions packages/mirai/lib/src/action_parsers/action_parsers.dart
Original file line number Diff line number Diff line change
@@ -6,3 +6,4 @@ export 'package:mirai/src/action_parsers/mirai_navigate_action/mirai_navigate_ac
export 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart';
export 'package:mirai/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart';
export 'package:mirai/src/action_parsers/mirai_snack_bar/mirai_snack_bar.dart';
export 'package:mirai/src/action_parsers/mirai_drawer_action/mirai_drawer_action_parser.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:mirai/mirai.dart';
import 'package:mirai/src/utils/action_type.dart';

class MiraiDrawerActionParser extends MiraiActionParser<dynamic> {
const MiraiDrawerActionParser();

@override
String get actionType => ActionType.openDrawer.name;

@override
getModel(Map<String, dynamic> json) => json;

@override
FutureOr onCall(BuildContext context, dynamic model) {
miraiScaffoldKey.currentState?.openDrawer();
}
}
2 changes: 2 additions & 0 deletions packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ class Mirai {
const MiraiAspectRatioParser(),
const MiraiFittedBoxParser(),
const MiraiLimitedBoxParser(),
const MiraiDrawerParser(),
];

static final _actionParsers = <MiraiActionParser>[
@@ -106,6 +107,7 @@ class Mirai {
const MiraiGetFormValueParser(),
const MiraiFormValidateParser(),
const MiraiSnackBarParser(),
const MiraiDrawerActionParser(),
];

static Future<void> initialize({
26 changes: 26 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_drawer/mirai_drawer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/widgets.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mirai/src/parsers/mirai_shape_border/mirai_shape_border.dart';

export 'package:mirai/src/parsers/mirai_drawer/mirai_drawer_parser.dart';

part 'mirai_drawer.freezed.dart';
part 'mirai_drawer.g.dart';

@freezed
class MiraiDrawer with _$MiraiDrawer {
const factory MiraiDrawer({
String? backgroundColor,
String? shadowColor,
String? surfaceTintColor,
String? semanticLabel,
double? elevation,
double? width,
MiraiShapeBorder? shape,
Clip? clipBehavior,
required Map<String, dynamic> child,
}) = _MiraiDrawer;

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