Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ark4579 committed Apr 11, 2021
1 parent bb42993 commit 24866d9
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/main/djs/code_djs/code_djs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export 'function_call.dart';
export 'function.dart';
export 'if_else.dart';
export 'stateless_widget.dart';
export 'return.dart';
3 changes: 3 additions & 0 deletions lib/main/djs/code_djs/code_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum CodePartType {
IfElse,
Import,
StatelessWidget,
Return,
}

@JsonSerializable()
Expand Down Expand Up @@ -38,6 +39,8 @@ class CodePartDj {
return ImportDj.fromJson(json);
case CodePartType.StatelessWidget:
return StatelessWidgetDj.fromJson(json);
case CodePartType.Return:
return ReturnDj.fromJson(json);
default:
throw Exception(
'CodePartDj.fromJson not handled for ${codePartDj.type}');
Expand Down
1 change: 1 addition & 0 deletions lib/main/djs/code_djs/code_part.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/main/djs/code_djs/function.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/main/djs/code_djs/function_call.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/main/djs/code_djs/if_else.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/main/djs/code_djs/import.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions lib/main/djs/code_djs/return.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:json_annotation/json_annotation.dart';
import 'code_part.dart';

part 'return.g.dart';

@JsonSerializable()
class ReturnDj extends CodePartDj {
@JsonKey(name: 'returnStr')
final String returnStr;

ReturnDj({
description,
this.returnStr = '',
CodePartType type = CodePartType.Return,
}) : super(
description: description,
type: type,
);

factory ReturnDj.fromJson(Map<String, dynamic> json) =>
_$ReturnDjFromJson(json);
@override
Map<String, dynamic> toJson() => _$ReturnDjToJson(this);

@override
List<String> lines() {
var _lines = super.lines();

var returnLine = 'return $returnStr;';

_lines.add(returnLine);
return _lines;
}
}
65 changes: 65 additions & 0 deletions lib/main/djs/code_djs/return.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions lib/main/djs/code_djs/stateless_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StatelessWidgetDj extends CodePartDj {
final List<FunctionArg>? args;

@JsonKey(name: 'body')
final CodePartDj? body;
final List<CodePartDj>? body;

StatelessWidgetDj({
description,
Expand All @@ -34,7 +34,10 @@ class StatelessWidgetDj extends CodePartDj {
List<String> lines() {
var _lines = super.lines();

var bodyLines = body?.lines() ?? [];
var bodyLines = [];
body?.forEach((body) {
bodyLines += body.lines();
});
var bodyStr = bodyLines.join(' ');

var contructorArgs = args?.map((e) => e.asConstructorArg()).toList() ?? [];
Expand All @@ -47,8 +50,7 @@ class StatelessWidgetDj extends CodePartDj {
var widgetLine = '';
widgetLine += 'class $name extends StatelessWidget {';
widgetLine += '$paramtersStr $name($argsLine);';
widgetLine +=
'@override Widget build(BuildContext context) { $bodyStr return Container();}';
widgetLine += '@override Widget build(BuildContext context) { $bodyStr }';
widgetLine += '}';

_lines.add(widgetLine);
Expand Down
9 changes: 5 additions & 4 deletions lib/main/djs/code_djs/stateless_widget.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24866d9

Please sign in to comment.