2023-04-01 16:52:13 +02:00

47 lines
1.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:manager_app/Components/string_input_container.dart';
import 'package:manager_api_new/api.dart';
import 'dart:convert';
class WebOrVideoConfig extends StatefulWidget {
final String? color;
final String? label;
final String initialValue;
final ValueChanged<String> onChanged; // To return video or web url
const WebOrVideoConfig({
Key? key,
this.color,
this.label,
required this.initialValue,
required this.onChanged,
}) : super(key: key);
@override
_WebOrVideoConfigState createState() => _WebOrVideoConfigState();
}
class _WebOrVideoConfigState extends State<WebOrVideoConfig> {
late WebDTO resourceSource; // WebDTO == VideoDTO
@override
void initState() {
WebDTO test = WebDTO.fromJson(json.decode(widget.initialValue))!;
resourceSource = test;
super.initState();
}
@override
Widget build(BuildContext context) {
return StringInputContainer(
label: widget.label!,
initialValue: resourceSource.source_ == null ? '': resourceSource.source_,
onChanged: (String url) {
resourceSource.source_ = url;
widget.onChanged(jsonEncode(resourceSource).toString());
},
isUrl: true,
);
}
}