Remove old create channel screen
This commit is contained in:
@@ -167,14 +167,6 @@ class ChannelListPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
child: Icon(Icons.add),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
|
|
||||||
return CreateChannelPage();
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
body: ChannelsBloc(
|
body: ChannelsBloc(
|
||||||
child: ChannelListView(
|
child: ChannelListView(
|
||||||
swipeToAction: true,
|
swipeToAction: true,
|
||||||
@@ -270,145 +262,6 @@ class ThreadPage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreateChannelPage extends StatefulWidget {
|
|
||||||
@override
|
|
||||||
_CreateChannelPageState createState() => _CreateChannelPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CreateChannelPageState extends State<CreateChannelPage> {
|
|
||||||
final selectedUsers = <User>{};
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
elevation: 0,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
title: Text(
|
|
||||||
'Create a channel',
|
|
||||||
style: Theme.of(context).textTheme.headline6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton:
|
|
||||||
selectedUsers.isNotEmpty ? _buildFAB(context) : null,
|
|
||||||
body: _buildListView(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildListView() {
|
|
||||||
return UsersBloc(
|
|
||||||
child: UserListView(
|
|
||||||
pagination: PaginationParams(
|
|
||||||
limit: 25,
|
|
||||||
),
|
|
||||||
sort: [
|
|
||||||
SortOption(
|
|
||||||
'name',
|
|
||||||
direction: SortOption.ASC,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
onUserLongPress: (user) {
|
|
||||||
_selectUser(user);
|
|
||||||
},
|
|
||||||
selectedUsers: selectedUsers,
|
|
||||||
onUserTap: (user, _) {
|
|
||||||
if (selectedUsers.isNotEmpty) {
|
|
||||||
return _selectUser(user);
|
|
||||||
}
|
|
||||||
_createChannel(context, [user]);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildFAB(BuildContext context) {
|
|
||||||
return FloatingActionButton(
|
|
||||||
child: Icon(Icons.done),
|
|
||||||
onPressed: () async {
|
|
||||||
String name;
|
|
||||||
if (selectedUsers.length > 1) {
|
|
||||||
name = await _showEnterNameDialog(context);
|
|
||||||
if (name?.isNotEmpty != true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_createChannel(context, selectedUsers.toList(), name);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String> _showEnterNameDialog(BuildContext context) {
|
|
||||||
final controller = TextEditingController();
|
|
||||||
return showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => SimpleDialog(
|
|
||||||
contentPadding: const EdgeInsets.all(16),
|
|
||||||
title: Text('Enter a name for the channel'),
|
|
||||||
children: [
|
|
||||||
TextField(
|
|
||||||
controller: controller,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ButtonBar(
|
|
||||||
children: [
|
|
||||||
FlatButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text('Cancel'),
|
|
||||||
),
|
|
||||||
FlatButton(
|
|
||||||
onPressed: () => Navigator.pop(context, controller.text),
|
|
||||||
child: Text('Ok'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _createChannel(
|
|
||||||
BuildContext context,
|
|
||||||
List<User> users, [
|
|
||||||
String name,
|
|
||||||
]) async {
|
|
||||||
final client = StreamChat.of(context).client;
|
|
||||||
final channel = client.channel('messaging', extraData: {
|
|
||||||
'members': [
|
|
||||||
client.state.user.id,
|
|
||||||
...users.map((e) => e.id),
|
|
||||||
],
|
|
||||||
if (name != null) 'name': name,
|
|
||||||
});
|
|
||||||
await channel.watch();
|
|
||||||
Navigator.pushReplacement(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) {
|
|
||||||
return StreamChannel(
|
|
||||||
child: ChannelPage(),
|
|
||||||
channel: channel,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _selectUser(User user) {
|
|
||||||
if (!selectedUsers.contains(user)) {
|
|
||||||
setState(() {
|
|
||||||
selectedUsers.add(user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
selectedUsers.remove(user);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NewChatScreen extends StatefulWidget {
|
class NewChatScreen extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_NewChatScreenState createState() => _NewChatScreenState();
|
_NewChatScreenState createState() => _NewChatScreenState();
|
||||||
|
|||||||
Reference in New Issue
Block a user