Skip to content

Commit

Permalink
[이우섭] 0108 textDataMap 제거, 테스트 위젯 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeUSeob committed Jan 8, 2024
1 parent b296d6a commit 3272f38
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 206 deletions.
171 changes: 6 additions & 165 deletions lib/test_text.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:myapp/vm_sdk/impl/vm_text_widget.dart';
import 'package:path/path.dart';
import 'vm_sdk/impl/global_helper.dart';
import 'vm_sdk/impl/resource_manager.dart';
import 'vm_sdk/impl/ffmpeg_manager.dart';
import 'vm_sdk/types/types.dart';

class TestWidget extends StatefulWidget {
TestWidget({Key? key}) : super(key: key);
const TestWidget({Key? key}) : super(key: key);

@override
State<TestWidget> createState() => _TestWidgetState();
}

class _TestWidgetState extends State<TestWidget> {
VMTextWidget _vmTextWidget = VMTextWidget();
final VMTextWidget _vmTextWidget = VMTextWidget();

List<String> imageList = [];
String _currentText = "";
Expand All @@ -27,15 +25,6 @@ class _TestWidgetState extends State<TestWidget> {

final FFMpegManager _ffmpegManager = FFMpegManager();

void updateTextCallback(int index, String text) async {
// await _vmTextWidget.setTextValue(index, text);

String? preview = _vmTextWidget.previewImagePath;
setState(() {
if (preview != null) imageList = [preview];
});
}

void _run() async {
try {
if (!_isInitialized) {
Expand Down Expand Up @@ -151,33 +140,6 @@ class _TestWidgetState extends State<TestWidget> {
}
}

List<Widget> rectangleBoxList(isPreview, index) {
List<Widget> list = [];

list.add(Image.file(
File(imageList[index]),
width: MediaQuery.of(this.context).size.width,
fit: BoxFit.fitWidth,
),
);

if (isPreview) {
final textList = _vmTextWidget.textDataMap.values.toList();
for (int i=0; i<textList.length; i++) {
final VMText vmText = textList[i];
list.add(RectangleBox(
index: i,
mediaWidth: MediaQuery.of(this.context).size.width,
width: _vmTextWidget.width,
height: _vmTextWidget.height,
vmText: vmText,
updateTextCallback: updateTextCallback,
));
}
}
return list;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -195,9 +157,10 @@ class _TestWidgetState extends State<TestWidget> {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
bool isPreview = imageList.length == 1;
return Stack(
children: rectangleBoxList(isPreview, index),
return Image.file(
File(imageList[index]),
width: MediaQuery.of(this.context).size.width,
fit: BoxFit.fitWidth,
);
},
),
Expand All @@ -212,125 +175,3 @@ class _TestWidgetState extends State<TestWidget> {
);
}
}

class RectangleBox extends StatefulWidget {
int index;
double mediaWidth;
double width;
double height;
VMText vmText;
var updateTextCallback;

RectangleBox({
Key? key,
required this.index,
required this.mediaWidth,
required this.width,
required this.height,
required this.vmText,
required this.updateTextCallback,
}) : super(key: key);

@override
State<RectangleBox> createState() => _RectangleBoxState();
}

class _RectangleBoxState extends State<RectangleBox> {
TextEditingController _textController = TextEditingController();

var _timer;
var _now;

@override
void initState() {
super.initState();
_textController.addListener(() {
_now = DateTime.now();
_timer = Timer(Duration(seconds: 1), () {
int diff = _now.difference(DateTime.now()).inSeconds;
if (diff <= -1) {
if (_textController.text.isEmpty) {
} else {
widget.updateTextCallback(widget.index, _textController.text);
}
}
});
});
}

@override
void dispose() {
_textController.dispose();
if (_timer != null) {
_timer.cancel();
}
super.dispose();
}

@override
Widget build(BuildContext context) {
Rectangle rectangle = widget.vmText.boundingBox;

final mediaHeight = widget.height * widget.mediaWidth / widget.width;

final x = widget.mediaWidth * rectangle.x / widget.width;
final y = mediaHeight * rectangle.y / widget.height;

final w = widget.mediaWidth * rectangle.width / widget.width;
final h = mediaHeight * rectangle.height / widget.height;

return Positioned(
top: y,
left: x,
child: GestureDetector(
onTap: () {
_textController.text = widget.vmText.value;
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(
bottom:
MediaQuery.of(context).viewInsets.bottom),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: TextFormField(
controller: _textController,
autofocus: true,
decoration: InputDecoration(
hintText: "Please enter text",
isDense: true,
filled: true,
),
),
),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Close"),
),
],
),
),
SizedBox(height: 10),
],
),
));
},
child: Container(
width: w,
height: h,
color: Colors.grey.shade800.withOpacity(0.3),
),
));
}
}
17 changes: 0 additions & 17 deletions lib/vm_sdk/impl/convert_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,6 @@ String parseAllEditedDataToJSON(AllEditedData allEditedData) {
final TextExportData? exportedText = editedText.textExportData;

if (exportedText != null) {
final Map textDataMap = {};

for (final key in exportedText.textDataMap.keys) {
VMText vmText = exportedText.textDataMap[key]!;
textDataMap[key] = {
"key": vmText.key,
"value": vmText.value,
"boundingBox": {
"x": vmText.boundingBox.x,
"y": vmText.boundingBox.y,
"width": vmText.boundingBox.width,
"height": vmText.boundingBox.height
}
};
}

overlays.add({
"id": uuid.v4(),
"type": "TEXT",
Expand All @@ -99,7 +83,6 @@ String parseAllEditedDataToJSON(AllEditedData allEditedData) {
"height": exportedText.height,
"frameRate": exportedText.frameRate,
"totalFrameCount": exportedText.totalFrameCount,
"textDataMap": textDataMap,
}
},
"scale": 1,
Expand Down
18 changes: 0 additions & 18 deletions lib/vm_sdk/impl/vm_text_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class VMTextWidget extends StatelessWidget {
double _frameRate = 0;
int _totalFrameCount = 0;
double _elapsedTime = 0;
Map<String, VMText> _textDataMap = {};

String? _previewImagePath;
String? _allSequencesPath;
Expand Down Expand Up @@ -87,8 +86,6 @@ class VMTextWidget extends StatelessWidget {

double get elapsedTime => _elapsedTime;

Map<String, VMText> get textDataMap => _textDataMap;

String? get previewImagePath => _previewImagePath;

String? get allSequencesPath => _allSequencesPath;
Expand Down Expand Up @@ -124,7 +121,6 @@ class VMTextWidget extends StatelessWidget {
print("_height : $_height ");
print("_frameRate : $_frameRate ");
print("_totalFrameCount : $_totalFrameCount ");
print("_textDataMap : $_textDataMap");
print("_allSequences : $_allSequencePaths");
}

Expand All @@ -151,7 +147,6 @@ class VMTextWidget extends StatelessWidget {
_height = 0;
_frameRate = 0;
_totalFrameCount = 0;
_textDataMap = {};
_allSequencePaths = [];
}

Expand Down Expand Up @@ -276,27 +271,14 @@ class VMTextWidget extends StatelessWidget {
try {
_width = args[0]["width"].toDouble();
_height = args[0]["height"].toDouble();
List textData = args[0]["textData"];
_frameRate = args[0]["frameRate"].toDouble();
_elapsedTime = args[0]["elapsedTime"].toDouble();
_textDataMap.clear();
_allSequencePaths.clear();

final preview = args[0]["preview"];
String previewUrl = "$_currentPreviewPath/preview.png";
writeFileFromBase64(previewUrl, preview.toString().replaceAll("data:image/png;base64,", ""));

for (int i = 0; i < textData.length; i++) {
print('key is ${textData[i]['key']}');
print('value is ${textData[i]['value']}');

_textDataMap[i.toString()] = VMText(
textData[i]['key'],
textData[i]['value'],
Rectangle(textData[i]['x'].toDouble(), textData[i]['y'].toDouble(), textData[i]['width'].toDouble(),
textData[i]['height'].toDouble()));
}

_previewImagePath = previewUrl;
_printAllData();

Expand Down
3 changes: 1 addition & 2 deletions lib/vm_sdk/types/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class TextExportData {
int totalFrameCount;
String previewImagePath;
String allSequencesPath;
Map<String, VMText> textDataMap;

TextExportData(this.id, this.width, this.height, this.frameRate, this.totalFrameCount,
this.previewImagePath, this.allSequencesPath, this.textDataMap);
this.previewImagePath, this.allSequencesPath);
}

class EditedTextData {
Expand Down
6 changes: 2 additions & 4 deletions lib/vm_sdk/vm_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ class VMSDKWidget extends StatelessWidget {
_textWidget.frameRate,
_textWidget.totalFrameCount,
_textWidget.previewImagePath ?? "",
_textWidget.allSequencesPath ?? "",
_textWidget.textDataMap);
_textWidget.allSequencesPath ?? "");

EditedTextData editedTextData = EditedTextData(
exportedText.id,
Expand Down Expand Up @@ -307,8 +306,7 @@ class VMSDKWidget extends StatelessWidget {
_textWidget.frameRate,
_textWidget.totalFrameCount,
_textWidget.previewImagePath!,
_textWidget.allSequencesPath!,
_textWidget.textDataMap);
_textWidget.allSequencesPath!);
}

final VideoGeneratedResult result = await _runFFmpeg(
Expand Down

0 comments on commit 3272f38

Please sign in to comment.