manager-app/lib/Screens/Resources/new_resource_popup.dart

104 lines
4.1 KiB
Dart

import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:manager_app/Components/message_notification.dart';
import 'package:manager_app/Components/resource_tab.dart';
import 'package:flutter/material.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart';
import 'package:manager_app/l10n/app_localizations.dart';
import 'package:manager_api_new/api.dart';
dynamic showNewResource(AppContext appContext, BuildContext context) async {
ResourceDTO resourceDetailDTO = new ResourceDTO();
List<File>? filesToSend;
List<PlatformFile>? filesToSendWeb;
var result = await showDialog(
builder: (BuildContext context) => Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
child: SizedBox(
width: 560,
child: Padding(
padding: const EdgeInsets.fromLTRB(24, 20, 24, 24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
AppLocalizations.of(context)!.newResource,
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.w400),
),
const SizedBox(height: 10),
SizedBox(
height: 400,
child: ResourceTab(
resourceDTO: resourceDetailDTO,
onFileUpload: (List<File> files) {
filesToSend = files;
},
onFileUploadWeb: (List<PlatformFile> files) {
filesToSendWeb = files;
},
),
),
],
),
),
),
const SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.end,
children: [
RoundedButton(
text: AppLocalizations.of(context)!.cancel,
icon: Icons.undo,
color: kSecond,
press: () => Navigator.of(context).pop(),
fontSize: 16,
),
RoundedButton(
text: AppLocalizations.of(context)!.create,
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
if (kIsWeb) {
if (resourceDetailDTO.url != null || filesToSendWeb != null) {
Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]);
} else {
showNotification(Colors.orange, kWhite, AppLocalizations.of(context)!.resourceNoFileLoaded, context, null);
}
} else {
if (resourceDetailDTO.url != null || filesToSendWeb!.length > 0 || filesToSend!.length > 0) {
Navigator.pop(context, [resourceDetailDTO, filesToSend, filesToSendWeb]);
} else {
showNotification(Colors.orange, kWhite, AppLocalizations.of(context)!.resourceNoFileLoaded, context, null);
}
}
},
fontSize: 16,
),
],
),
],
),
),
),
), context: context
);
return result;
}