146 lines
5.2 KiB
Dart
146 lines
5.2 KiB
Dart
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:loader_overlay/loader_overlay.dart';
|
|
import 'package:marianum_mobile/widget/filePick.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../api/marianumcloud/talk/sendMessage/sendMessage.dart';
|
|
import '../../../api/marianumcloud/talk/sendMessage/sendMessageParams.dart';
|
|
import '../../../data/chatList/chatProps.dart';
|
|
|
|
class ChatTextfield extends StatefulWidget {
|
|
String sendToToken;
|
|
ChatTextfield(this.sendToToken, {Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<ChatTextfield> createState() => _ChatTextfieldState();
|
|
}
|
|
|
|
class _ChatTextfieldState extends State<ChatTextfield> {
|
|
final TextEditingController _textBoxController = TextEditingController();
|
|
bool sending = false;
|
|
bool isLoading = false;
|
|
|
|
void mediaUpload(String? path) {
|
|
if(path == null) {
|
|
context.loaderOverlay.hide();
|
|
return;
|
|
}
|
|
|
|
showDialog(context: context, builder: (context) {
|
|
return AlertDialog(
|
|
title: const Text("Datei senden"),
|
|
content: Image.file(File(path)),
|
|
actions: [
|
|
TextButton(onPressed: () {
|
|
Navigator.of(context).pop();
|
|
context.loaderOverlay.hide();
|
|
}, child: const Text("Abbrechen")),
|
|
TextButton(onPressed: () {
|
|
context.loaderOverlay.hide();
|
|
}, child: const Text("Senden")),
|
|
],
|
|
);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: <Widget>[
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Container(
|
|
padding: const EdgeInsets.only(left: 10, bottom: 10, top: 10),
|
|
height: 60,
|
|
width: double.infinity,
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
child: Row(
|
|
children: <Widget>[
|
|
GestureDetector(
|
|
onTap: (){
|
|
showDialog(context: context, builder: (context) {
|
|
return SimpleDialog(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.file_open),
|
|
title: const Text("Aus Dateien auswählen"),
|
|
onTap: () {
|
|
context.loaderOverlay.show();
|
|
FilePick.documentPick().then((value) {
|
|
log(value ?? "?");
|
|
mediaUpload(value);
|
|
});
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.image),
|
|
title: const Text("Aus Gallerie auswählen"),
|
|
onTap: () {
|
|
context.loaderOverlay.show();
|
|
FilePick.galleryPick().then((value) {
|
|
log(value?.path ?? "?");
|
|
mediaUpload(value?.path);
|
|
});
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
});
|
|
},
|
|
child: Container(
|
|
height: 30,
|
|
width: 30,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).primaryColor,
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
child: const Icon(Icons.add, color: Colors.white, size: 20, ),
|
|
),
|
|
),
|
|
const SizedBox(width: 15),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: _textBoxController,
|
|
readOnly: sending,
|
|
maxLines: 10,
|
|
decoration: InputDecoration(
|
|
hintText: "Nachricht schreiben...",
|
|
hintStyle: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
|
|
border: InputBorder.none
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 15),
|
|
FloatingActionButton(
|
|
onPressed: (){
|
|
if(_textBoxController.text.isEmpty) return;
|
|
setState(() {
|
|
sending = true;
|
|
});
|
|
SendMessage(widget.sendToToken, SendMessageParams(_textBoxController.text)).run().then((value) => {
|
|
Provider.of<ChatProps>(context, listen: false).run(),
|
|
_textBoxController.text = "",
|
|
setState(() {
|
|
sending = false;
|
|
}),
|
|
});
|
|
},
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
elevation: 0,
|
|
child: const Icon(Icons.send, color: Colors.white, size: 18),
|
|
),
|
|
],
|
|
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|