1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-30 23:08:50 +00:00
comunicmobile/lib/ui/dialogs/input_youtube_link_dialog.dart

30 lines
1010 B
Dart

import 'package:comunic/ui/dialogs/single_input_dialog.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Add YouTube link dialog
///
/// @author Pierre Hubert
/// Ask the user to input a YouTube ID
Future<String> showInputYouTubeIDDialog(
BuildContext context, String initialID) async {
final value = await showDialog<String>(
context: context,
builder: (b) => SingleInputDialog(
title: tr("Input YouTube URL"),
icon: Icons.ondemand_video,
initialValue: initialID == null
? null
: "https://www.youtube.com/watch/?v=" + initialID,
label: tr("https://www.youtube.com/watch/?v="),
checkInput: (s) => RegExp(r'watch\/\?v=[\w\-\_]+').hasMatch(s),
errorMessage: tr("Invalid YouTube link!"),
));
if (value == null) return null;
return value.split("v=")[1].split("&")[0].split("#")[0];
}