changed everything from filcnaplo to refilc finally
This commit is contained in:
240
refilc_mobile_ui/lib/pages/messages/messages_page.dart
Normal file
240
refilc_mobile_ui/lib/pages/messages/messages_page.dart
Normal file
@@ -0,0 +1,240 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:refilc/api/providers/update_provider.dart';
|
||||
import 'package:refilc/ui/date_widget.dart';
|
||||
import 'package:refilc_kreta_api/providers/message_provider.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/models/message.dart';
|
||||
import 'package:refilc_mobile_ui/common/bottom_sheet_menu/rounded_bottom_sheet.dart';
|
||||
import 'package:refilc_mobile_ui/common/empty.dart';
|
||||
import 'package:refilc_mobile_ui/common/filter_bar.dart';
|
||||
import 'package:refilc_mobile_ui/common/profile_image/profile_button.dart';
|
||||
import 'package:refilc_mobile_ui/common/profile_image/profile_image.dart';
|
||||
import 'package:refilc/ui/filter/sort.dart';
|
||||
// import 'package:refilc_mobile_ui/common/soon_alert/soon_alert.dart';
|
||||
import 'package:refilc_mobile_ui/common/widgets/message/message_viewable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'messages_page.i18n.dart';
|
||||
import 'send_message/send_message.dart';
|
||||
|
||||
class MessagesPage extends StatefulWidget {
|
||||
const MessagesPage({super.key});
|
||||
|
||||
@override
|
||||
MessagesPageState createState() => MessagesPageState();
|
||||
}
|
||||
|
||||
class MessagesPageState extends State<MessagesPage>
|
||||
with TickerProviderStateMixin {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
late UserProvider user;
|
||||
late MessageProvider messageProvider;
|
||||
late UpdateProvider updateProvider;
|
||||
late String firstName;
|
||||
late TabController tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
tabController = TabController(length: 4, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
user = Provider.of<UserProvider>(context);
|
||||
messageProvider = Provider.of<MessageProvider>(context);
|
||||
updateProvider = Provider.of<UpdateProvider>(context);
|
||||
|
||||
List<String> nameParts = user.displayName?.split(" ") ?? ["?"];
|
||||
firstName = nameParts.length > 1 ? nameParts[1] : nameParts[0];
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(top: 12.0),
|
||||
child: NestedScrollView(
|
||||
physics: const BouncingScrollPhysics(
|
||||
parent: AlwaysScrollableScrollPhysics()),
|
||||
headerSliverBuilder: (context, _) => [
|
||||
SliverAppBar(
|
||||
pinned: true,
|
||||
floating: false,
|
||||
snap: false,
|
||||
centerTitle: false,
|
||||
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8.0, vertical: 5.0),
|
||||
child: IconButton(
|
||||
splashRadius: 24.0,
|
||||
onPressed: () async {
|
||||
// Navigator.of(context, rootNavigator: true)
|
||||
// .push(PageRouteBuilder(
|
||||
// pageBuilder: (context, animation, secondaryAnimation) =>
|
||||
// PremiumFSTimetable(
|
||||
// controller: controller,
|
||||
// ),
|
||||
// ))
|
||||
// .then((_) {
|
||||
// SystemChrome.setPreferredOrientations(
|
||||
// [DeviceOrientation.portraitUp]);
|
||||
// setSystemChrome(context);
|
||||
// });
|
||||
// SoonAlert.show(context: context);
|
||||
await showSendMessageSheet(context);
|
||||
},
|
||||
icon: Icon(
|
||||
FeatherIcons.send,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Profile Icon
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 24.0),
|
||||
child: ProfileButton(
|
||||
child: ProfileImage(
|
||||
heroTag: "profile",
|
||||
name: firstName,
|
||||
backgroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary, //ColorUtils.stringToColor(user.displayName ?? "?"),
|
||||
badge: updateProvider.available,
|
||||
role: user.role,
|
||||
profilePictureString: user.picture,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
automaticallyImplyLeading: false,
|
||||
shadowColor: Theme.of(context).shadowColor,
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Text(
|
||||
"Messages".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text,
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
bottom: FilterBar(
|
||||
items: [
|
||||
Tab(text: "Inbox".i18n),
|
||||
Tab(text: "Sent".i18n),
|
||||
Tab(text: "Trash".i18n),
|
||||
Tab(text: "Draft".i18n),
|
||||
],
|
||||
controller: tabController,
|
||||
disableFading: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
body: TabBarView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
controller: tabController,
|
||||
children: List.generate(
|
||||
4, (index) => filterViewBuilder(context, index))),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<DateWidget> getFilterWidgets(MessageType activeData) {
|
||||
List<DateWidget> items = [];
|
||||
switch (activeData) {
|
||||
case MessageType.inbox:
|
||||
for (var message in messageProvider.messages) {
|
||||
if (message.type == MessageType.inbox) {
|
||||
items.add(DateWidget(
|
||||
date: message.date,
|
||||
widget: MessageViewable(message),
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MessageType.sent:
|
||||
for (var message in messageProvider.messages) {
|
||||
if (message.type == MessageType.sent) {
|
||||
items.add(DateWidget(
|
||||
date: message.date,
|
||||
widget: MessageViewable(message),
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MessageType.trash:
|
||||
for (var message in messageProvider.messages) {
|
||||
if (message.type == MessageType.trash) {
|
||||
items.add(DateWidget(
|
||||
date: message.date,
|
||||
widget: MessageViewable(message),
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MessageType.draft:
|
||||
for (var message in messageProvider.messages) {
|
||||
if (message.type == MessageType.draft) {
|
||||
items.add(DateWidget(
|
||||
date: message.date,
|
||||
widget: MessageViewable(message),
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
Widget filterViewBuilder(context, int activeData) {
|
||||
List<Widget> filterWidgets = sortDateWidgets(context,
|
||||
dateWidgets: getFilterWidgets(MessageType.values[activeData]),
|
||||
hasShadow: true);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12.0),
|
||||
child: RefreshIndicator(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
onRefresh: () {
|
||||
return Future.wait([
|
||||
messageProvider.fetch(type: MessageType.inbox),
|
||||
messageProvider.fetch(type: MessageType.sent),
|
||||
messageProvider.fetch(type: MessageType.trash),
|
||||
]);
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
itemBuilder: (context, index) => filterWidgets.isNotEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24.0, vertical: 6.0),
|
||||
child: filterWidgets[index],
|
||||
)
|
||||
: Empty(subtitle: "empty".i18n),
|
||||
itemCount: max(filterWidgets.length, 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showSendMessageSheet(BuildContext context) async {
|
||||
await messageProvider.fetchAllRecipients();
|
||||
|
||||
_scaffoldKey.currentState?.showBottomSheet(
|
||||
(context) => RoundedBottomSheet(
|
||||
borderRadius: 14.0,
|
||||
child: SendMessageSheet(messageProvider.recipients)),
|
||||
backgroundColor: const Color(0x00000000),
|
||||
elevation: 12.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
36
refilc_mobile_ui/lib/pages/messages/messages_page.i18n.dart
Normal file
36
refilc_mobile_ui/lib/pages/messages/messages_page.i18n.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
"Messages": "Messages",
|
||||
"Inbox": "Inbox",
|
||||
"Sent": "Sent",
|
||||
"Trash": "Trash",
|
||||
"Draft": "Draft",
|
||||
"empty": "You have no messages.",
|
||||
},
|
||||
"hu_hu": {
|
||||
"Messages": "Üzenetek",
|
||||
"Inbox": "Beérkezett",
|
||||
"Sent": "Elküldött",
|
||||
"Trash": "Kuka",
|
||||
"Draft": "Piszkozat",
|
||||
"empty": "Nincsenek üzeneteid.",
|
||||
},
|
||||
"de_de": {
|
||||
"Messages": "Nachrichten",
|
||||
"Inbox": "Posteingang",
|
||||
"Sent": "Gesendet",
|
||||
"Trash": "Müll",
|
||||
"Draft": "Entwurf",
|
||||
"empty": "Sie haben keine Nachrichten.",
|
||||
},
|
||||
};
|
||||
|
||||
String get i18n => localize(this, _t);
|
||||
String fill(List<Object> params) => localizeFill(this, params);
|
||||
String plural(int value) => localizePlural(value, this, _t);
|
||||
String version(Object modifier) => localizeVersion(modifier, this, _t);
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/models/message.dart';
|
||||
import 'package:refilc_kreta_api/providers/message_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/custom_snack_bar.dart';
|
||||
// import 'package:refilc_mobile_ui/common/custom_snack_bar.dart';
|
||||
import 'package:refilc_mobile_ui/common/material_action_button.dart';
|
||||
import 'package:refilc_mobile_ui/pages/messages/send_message/send_message.i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SendMessageSheet extends StatefulWidget {
|
||||
const SendMessageSheet(this.availableRecipients, {super.key});
|
||||
|
||||
final List<SendRecipient> availableRecipients;
|
||||
|
||||
@override
|
||||
SendMessageSheetState createState() => SendMessageSheetState();
|
||||
}
|
||||
|
||||
class SendMessageSheetState extends State<SendMessageSheet> {
|
||||
late MessageProvider messageProvider;
|
||||
|
||||
final _subjectController = TextEditingController();
|
||||
final _messageController = TextEditingController();
|
||||
|
||||
double newValue = 5.0;
|
||||
double newWeight = 100.0;
|
||||
|
||||
List<SendRecipient> selectedRecipients = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
messageProvider = Provider.of<MessageProvider>(context);
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Text(
|
||||
"send_message".i18n,
|
||||
style:
|
||||
const TextStyle(fontSize: 20.0, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
|
||||
// message recipients
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: DropdownButton2(
|
||||
items: widget.availableRecipients
|
||||
.map((item) => DropdownMenuItem<String>(
|
||||
value: item.kretaId.toString(),
|
||||
child: Text(
|
||||
"${item.name ?? (item.id ?? 'Nincs név').toString()}${item.type.code != 'TANAR' ? " (${item.type.shortName})" : ''}",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (String? v) async {
|
||||
int kretaId = int.parse(v ?? '0');
|
||||
|
||||
setState(() {
|
||||
selectedRecipients.add(widget.availableRecipients
|
||||
.firstWhere((e) => e.kretaId == kretaId));
|
||||
|
||||
widget.availableRecipients
|
||||
.removeWhere((e) => e.kretaId == kretaId);
|
||||
});
|
||||
},
|
||||
iconSize: 14,
|
||||
iconEnabledColor: AppColors.of(context).text,
|
||||
iconDisabledColor: AppColors.of(context).text,
|
||||
underline: const SizedBox(),
|
||||
itemHeight: 40,
|
||||
itemPadding: const EdgeInsets.only(left: 14, right: 14),
|
||||
buttonWidth: 50,
|
||||
dropdownWidth: 300,
|
||||
dropdownPadding: null,
|
||||
buttonDecoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
dropdownDecoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
dropdownElevation: 8,
|
||||
scrollbarRadius: const Radius.circular(40),
|
||||
scrollbarThickness: 6,
|
||||
scrollbarAlwaysShow: true,
|
||||
offset: const Offset(-10, -10),
|
||||
buttonSplashColor: Colors.transparent,
|
||||
customButton: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey, width: 2),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
|
||||
child: Text(
|
||||
selectedRecipients.isEmpty
|
||||
? "select_recipient".i18n
|
||||
: selectedRecipients
|
||||
.map((e) =>
|
||||
'${e.name ?? (e.id ?? 'Nincs név').toString()}, ')
|
||||
.join(),
|
||||
style: Theme.of(context).textTheme.titleSmall!.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.of(context).text.withOpacity(0.75)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Row(children: buildRecipientTiles()),
|
||||
|
||||
// message content
|
||||
Column(children: [
|
||||
Container(
|
||||
// width: 180.0,
|
||||
padding: const EdgeInsets.only(right: 12.0, left: 12.0),
|
||||
child: Center(
|
||||
child: TextField(
|
||||
controller: _subjectController,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600, fontSize: 18.0),
|
||||
autocorrect: true,
|
||||
textAlign: TextAlign.left,
|
||||
keyboardType: TextInputType.text,
|
||||
inputFormatters: [
|
||||
LengthLimitingTextInputFormatter(100),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
// border: InputBorder.none,
|
||||
// enabledBorder: InputBorder.none,
|
||||
// focusedBorder: InputBorder.none,
|
||||
hintText: "message_subject".i18n,
|
||||
suffixStyle: const TextStyle(fontSize: 16.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 200,
|
||||
padding: const EdgeInsets.only(right: 12.0, left: 12.0),
|
||||
child: TextField(
|
||||
controller: _messageController,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500, fontSize: 16.0),
|
||||
autocorrect: true,
|
||||
textAlign: TextAlign.left,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: 10,
|
||||
minLines: 1,
|
||||
inputFormatters: [
|
||||
LengthLimitingTextInputFormatter(500),
|
||||
],
|
||||
decoration: InputDecoration(
|
||||
// border: InputBorder.none,
|
||||
// enabledBorder: InputBorder.none,
|
||||
// focusedBorder: InputBorder.none,
|
||||
hintText: "message_text".i18n,
|
||||
suffixStyle: const TextStyle(fontSize: 14.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
Container(
|
||||
width: 120.0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
||||
child: MaterialActionButton(
|
||||
child: Text("send".i18n),
|
||||
onPressed: () async {
|
||||
if (_messageController.text.replaceAll(' ', '') == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
String subjectText =
|
||||
_subjectController.text.replaceAll(' ', '') != ''
|
||||
? _subjectController.text
|
||||
: 'Nincs tárgy';
|
||||
|
||||
var res = await messageProvider.sendMessage(
|
||||
recipients: selectedRecipients,
|
||||
subject: subjectText,
|
||||
messageText: _messageController.text,
|
||||
);
|
||||
|
||||
// do after send
|
||||
if (res == 'send_permission_error') {
|
||||
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
|
||||
content: Text('cant_send'.i18n), context: context));
|
||||
}
|
||||
|
||||
if (res == 'successfully_sent') {
|
||||
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
|
||||
content: Text('sent'.i18n), context: context));
|
||||
}
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
"recipients": "Recipients",
|
||||
"send_message": "Send Message",
|
||||
"send": "Send",
|
||||
"sent": "Message sent successfully.",
|
||||
"message_subject": "Subject...",
|
||||
"message_text": "Message text...",
|
||||
"select_recipient": "Add Recipient",
|
||||
"cant_send": "You can't send a message to one of the recipients!",
|
||||
},
|
||||
"hu_hu": {
|
||||
"recipients": "Címzettek",
|
||||
"send_message": "Üzenetküldés",
|
||||
"send": "Küldés",
|
||||
"sent": "Sikeres üzenetküldés.",
|
||||
"message_subject": "Tárgy...",
|
||||
"message_text": "Üzenet szövege...",
|
||||
"select_recipient": "Címzett hozzáadása",
|
||||
"cant_send": "Az egyik címzettnek nem küldhetsz üzenetet!",
|
||||
},
|
||||
"de_de": {
|
||||
"recipients": "Empfänger",
|
||||
"send_message": "Nachricht senden",
|
||||
"send": "Versenden",
|
||||
"sent": "Nachricht erfolgreich gesendet.",
|
||||
"message_subject": "Betreff...",
|
||||
"message_text": "Nachrichtentext...",
|
||||
"select_recipient": "Empfänger hinzufügen",
|
||||
"cant_send": "Neki nem küldhetsz üzenetet!",
|
||||
},
|
||||
};
|
||||
|
||||
String get i18n => localize(this, _t);
|
||||
String fill(List<Object> params) => localizeFill(this, params);
|
||||
String plural(int value) => localizePlural(value, this, _t);
|
||||
String version(Object modifier) => localizeVersion(modifier, this, _t);
|
||||
}
|
||||
Reference in New Issue
Block a user