feat: Added change name, group name, etc

This commit is contained in:
Deven Joshi
2020-12-15 19:47:21 +05:30
parent f2a707bc45
commit d2a115be6f
+81 -4
View File
@@ -27,6 +27,11 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
Timer _debounce; Timer _debounce;
Function modalSetStateCallback; Function modalSetStateCallback;
final FocusNode _focusNode = FocusNode();
bool namedChanged = false;
String changedName = '';
void _userNameListener() { void _userNameListener() {
if (_debounce?.isActive ?? false) _debounce.cancel(); if (_debounce?.isActive ?? false) _debounce.cancel();
_debounce = Timer(const Duration(milliseconds: 350), () { _debounce = Timer(const Duration(milliseconds: 350), () {
@@ -49,6 +54,10 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
_nameController = TextEditingController.fromValue( _nameController = TextEditingController.fromValue(
TextEditingValue(text: channel.channel.extraData['name'])); TextEditingValue(text: channel.channel.extraData['name']));
_searchController = TextEditingController()..addListener(_userNameListener); _searchController = TextEditingController()..addListener(_userNameListener);
_nameController.addListener(() {
setState(() {});
});
} }
@override @override
@@ -74,10 +83,19 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
title: Column( title: Column(
children: [ children: [
// TODO: Add member names instead of Demo (if name = null) // TODO: Add member names instead of Demo (if name = null)
Text( FutureBuilder<QueryMembersResponse>(
channel.channel.extraData['name'] ?? 'Demo', future: _memberQueryFuture,
style: TextStyle(color: Colors.black), builder: (context, snapshot) {
), return Text(
_getChannelName(MediaQuery.of(context).size.width,
members: snapshot.data?.members
?.map((e) => e.user)
?.toList()),
style: TextStyle(color: Colors.black),
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
}),
SizedBox( SizedBox(
height: 3.0, height: 3.0,
), ),
@@ -208,6 +226,9 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
} }
Widget _buildNameTile() { Widget _buildNameTile() {
var channel = StreamChannel.of(context).channel;
var channelName = channel.extraData['name'];
return Material( return Material(
color: Colors.white, color: Colors.white,
child: Container( child: Container(
@@ -228,6 +249,7 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
), ),
Expanded( Expanded(
child: TextField( child: TextField(
focusNode: _focusNode,
controller: _nameController, controller: _nameController,
cursorColor: Colors.black, cursorColor: Colors.black,
decoration: InputDecoration.collapsed( decoration: InputDecoration.collapsed(
@@ -242,6 +264,48 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
), ),
), ),
), ),
if ((channelName == null) ||
(channelName != _nameController.text.trim()))
Row(
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
child: StreamSvgIcon.close_small(),
onTap: () {
setState(() {
_nameController.text =
_getChannelName(MediaQuery.of(context).size.width);
_focusNode.unfocus();
});
},
),
Padding(
padding: const EdgeInsets.only(right: 16.0, left: 8.0),
child: InkWell(
child: StreamSvgIcon.check(
color: StreamChatTheme.of(context).accentColor,
size: 24.0,
),
onTap: () {
StreamChannel.of(context).channel.update({
'name': _nameController.text.trim(),
}).then((value) {
setState(() {
_focusNode.unfocus();
namedChanged = true;
changedName = _nameController.text.trim();
});
}).catchError((err) {
setState(() {
_nameController.text = channelName;
_focusNode.unfocus();
});
});
},
),
),
],
),
], ],
), ),
), ),
@@ -492,6 +556,19 @@ class _GroupInfoScreenState extends State<GroupInfoScreen> {
); );
} }
String _getChannelName(double width, {List<User> members}) {
if (namedChanged) {
return changedName;
}
if (StreamChannel.of(context).channel.extraData['name'] == null &&
members != null) {
return '${members[0].name} & ${members.length - 1} others';
}
return StreamChannel.of(context).channel.extraData['name'] ?? '';
}
String _getLastSeen(User user) { String _getLastSeen(User user) {
if (user.online) { if (user.online) {
return 'Online'; return 'Online';