flutter_app/lib/views/groupsettingsview.dart

199 lines
8.4 KiB
Dart
Raw Normal View History

2021-06-03 18:32:25 +00:00
import 'package:cwtch/cwtch_icons_icons.dart';
2021-04-23 19:57:30 +00:00
import 'package:flutter/services.dart';
2021-05-19 21:39:52 +00:00
import 'package:cwtch/model.dart';
import 'package:cwtch/widgets/buttontextfield.dart';
import 'package:cwtch/widgets/cwtchlabel.dart';
2021-04-23 19:57:30 +00:00
import 'package:flutter/material.dart';
2021-05-19 21:39:52 +00:00
import 'package:cwtch/settings.dart';
import 'package:cwtch/widgets/textfield.dart';
2021-04-23 19:57:30 +00:00
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../main.dart';
/// Group Settings View Provides way to Configure group settings
class GroupSettingsView extends StatefulWidget {
@override
_GroupSettingsViewState createState() => _GroupSettingsViewState();
}
class _GroupSettingsViewState extends State<GroupSettingsView> {
@override
void dispose() {
super.dispose();
}
final ctrlrNick = TextEditingController(text: "");
final ctrlrGroupAddr = TextEditingController(text: "");
2021-04-23 19:57:30 +00:00
@override
void initState() {
super.initState();
final nickname = Provider.of<ContactInfoState>(context, listen: false).nickname;
if (nickname.isNotEmpty) {
ctrlrNick.text = nickname;
}
final groupAddr = Provider.of<ContactInfoState>(context, listen: false).onion;
if (groupAddr.isNotEmpty) {
ctrlrGroupAddr.text = groupAddr;
}
2021-04-23 19:57:30 +00:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-05-25 00:11:39 +00:00
title: Text(Provider.of<ContactInfoState>(context).nickname + " " + AppLocalizations.of(context)!.conversationSettings),
2021-04-23 19:57:30 +00:00
),
body: _buildSettingsList(),
);
}
Widget _buildSettingsList() {
return Consumer<Settings>(builder: (context, settings, child) {
return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
return Scrollbar(
isAlwaysShown: true,
child: SingleChildScrollView(
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(2),
2021-04-23 19:57:30 +00:00
child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
// Nickname Save Button
2021-04-23 19:57:30 +00:00
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
CwtchLabel(label: AppLocalizations.of(context)!.displayNameLabel),
2021-04-23 19:57:30 +00:00
SizedBox(
height: 20,
),
CwtchButtonTextField(
controller: ctrlrNick,
readonly: false,
onPressed: () {
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var handle = Provider.of<ContactInfoState>(context, listen: false).onion;
Provider.of<ContactInfoState>(context, listen: false).nickname = ctrlrNick.text;
Provider.of<FlwtchState>(context, listen: false).cwtch.SetGroupAttribute(profileOnion, handle, "local.name", ctrlrNick.text);
// todo translations
final snackBar = SnackBar(content: Text("Group Nickname changed successfully"));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
icon: Icon(Icons.save),
tooltip: AppLocalizations.of(context)!.saveBtn,
2021-04-23 19:57:30 +00:00
)
]),
// Address Copy Button
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
CwtchLabel(label: AppLocalizations.of(context)!.groupAddr),
SizedBox(
height: 20,
),
CwtchTextField(
controller: ctrlrGroupAddr,
2021-05-25 00:11:39 +00:00
labelText: '',
validator: (value) {},
)
]),
2021-04-23 19:57:30 +00:00
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
CwtchLabel(label: AppLocalizations.of(context)!.server),
2021-04-23 19:57:30 +00:00
SizedBox(
height: 20,
),
CwtchTextField(
controller: TextEditingController(text: Provider.of<ContactInfoState>(context, listen: false).server),
validator: (value) {},
labelText: '',
2021-04-23 19:57:30 +00:00
)
]),
2021-04-23 19:57:30 +00:00
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
SizedBox(
height: 20,
),
2021-05-25 00:11:39 +00:00
CwtchLabel(label: AppLocalizations.of(context)!.conversationSettings),
2021-04-23 19:57:30 +00:00
SizedBox(
height: 20,
),
// TODO
]),
Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [
SizedBox(
height: 20,
),
Tooltip(
2021-06-03 18:32:25 +00:00
message: AppLocalizations.of(context)!.leaveGroup,
child: ElevatedButton.icon(
onPressed: () {
showAlertDialog(context);
},
2021-06-04 23:05:45 +00:00
icon: Icon(CwtchIcons.leave_group),
label: Text(AppLocalizations.of(context)!.leaveGroup),
))
])
2021-04-23 19:57:30 +00:00
])))));
});
});
}
void _copyOnion() {
Clipboard.setData(new ClipboardData(text: Provider.of<ContactInfoState>(context, listen: false).onion));
2021-05-25 00:11:39 +00:00
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedClipboardNotification));
2021-04-23 19:57:30 +00:00
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
showAlertDialog(BuildContext context) {
// set up the buttons
Widget cancelButton = TextButton(
2021-06-15 00:38:07 +00:00
child: Text(AppLocalizations.of(context)!.cancel),
style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
);
Widget continueButton = TextButton(
style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))),
child: Text(AppLocalizations.of(context)!.yesLeave),
onPressed: () {
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var handle = Provider.of<ContactInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(context, listen: false).cwtch.LeaveGroup(profileOnion, handle);
Future.delayed(Duration(milliseconds: 500), () {
Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog
});
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text(AppLocalizations.of(context)!.reallyLeaveThisGroupPrompt),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
2021-04-23 19:57:30 +00:00
}