1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00
comunicmobile/lib/ui/dialogs/input_youtube_link_dialog.dart

29 lines
974 B
Dart
Raw Permalink Normal View History

2020-04-25 15:16:33 +00:00
import 'package:comunic/ui/dialogs/single_input_dialog.dart';
import 'package:comunic/utils/intl_utils.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 {
2020-04-25 15:16:33 +00:00
final value = await showDialog<String>(
context: context,
builder: (b) => SingleInputDialog(
title: tr("Input YouTube URL")!,
2020-04-25 15:16:33 +00:00
icon: Icons.ondemand_video,
initialValue: initialID == null
? null
: "https://www.youtube.com/watch/?v=" + initialID,
label: tr("https://www.youtube.com/watch/?v=")!,
2020-04-25 15:16:33 +00:00
checkInput: (s) => RegExp(r'watch\/\?v=[\w\-\_]+').hasMatch(s),
errorMessage: tr("Invalid YouTube link!")!,
2020-04-25 15:16:33 +00:00
));
if (value == null) return null;
return value.split("v=")[1].split("&")[0].split("#")[0];
}