removed deprecated uses, fmt

This commit is contained in:
Deven Joshi
2021-05-17 14:40:50 +05:30
parent 0303e18945
commit 1ba92a8676
24 changed files with 208 additions and 96 deletions
@@ -43,8 +43,10 @@ class ChatView extends StatelessWidget {
name = channel.extraData['name'];
image = channel.extraData['image'];
} else {
final friend =
channel.state.members.where((element) => element.userId != currentUser.id).first.user;
final friend = channel.state.members
.where((element) => element.userId != currentUser.id)
.first
.user;
name = friend.name;
image = friend.extraData['image'];
}
@@ -13,21 +13,27 @@ class FriendsSelectionCubit extends Cubit<List<ChatUserState>> {
FriendsSelectionCubit(this._streamApiRepository) : super([]);
final StreamApiRepository _streamApiRepository;
List<ChatUserState> get selectedUsers => state.where((element) => element.selected).toList();
List<ChatUserState> get selectedUsers =>
state.where((element) => element.selected).toList();
Future<void> init() async {
final chatUsers = (await _streamApiRepository.getChatUsers()).map((e) => ChatUserState(e)).toList();
final chatUsers = (await _streamApiRepository.getChatUsers())
.map((e) => ChatUserState(e))
.toList();
emit(chatUsers);
}
void selectUser(ChatUserState chatUser) {
final index = state.indexWhere((element) => element.chatUser.id == chatUser.chatUser.id);
state[index] = ChatUserState(state[index].chatUser, selected: !chatUser.selected);
final index = state
.indexWhere((element) => element.chatUser.id == chatUser.chatUser.id);
state[index] =
ChatUserState(state[index].chatUser, selected: !chatUser.selected);
emit(List<ChatUserState>.from(state));
}
Future<Channel> createFriendChannel(ChatUserState chatUserState) async {
return await _streamApiRepository.createSimpleChat(chatUserState.chatUser.id);
return await _streamApiRepository
.createSimpleChat(chatUserState.chatUser.id);
}
}
@@ -7,8 +7,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
class FriendsSelectionView extends StatelessWidget {
void _createFriendChannel(BuildContext context, ChatUserState chatUserState) async {
final channel = await context.read<FriendsSelectionCubit>().createFriendChannel(chatUserState);
void _createFriendChannel(
BuildContext context, ChatUserState chatUserState) async {
final channel = await context
.read<FriendsSelectionCubit>()
.createFriendChannel(chatUserState);
pushAndReplaceToPage(
context,
Scaffold(
@@ -26,19 +29,23 @@ class FriendsSelectionView extends StatelessWidget {
final accentColor = Theme.of(context).accentColor;
return MultiBlocProvider(
providers: [
BlocProvider(create: (context) => FriendsSelectionCubit(context.read())..init()),
BlocProvider(
create: (context) => FriendsSelectionCubit(context.read())..init()),
BlocProvider(create: (_) => FriendsGroupCubit()),
],
child: BlocBuilder<FriendsGroupCubit, bool>(builder: (context, isGroup) {
return BlocBuilder<FriendsSelectionCubit, List<ChatUserState>>(builder: (context, snapshot) {
final selectedUsers = context.read<FriendsSelectionCubit>().selectedUsers;
return BlocBuilder<FriendsSelectionCubit, List<ChatUserState>>(
builder: (context, snapshot) {
final selectedUsers =
context.read<FriendsSelectionCubit>().selectedUsers;
return Scaffold(
floatingActionButton: isGroup && selectedUsers.isNotEmpty
? FloatingActionButton(
child: Icon(Icons.arrow_right_alt_rounded),
onPressed: () {
pushAndReplaceToPage(context, GroupSelectionView(selectedUsers));
pushAndReplaceToPage(
context, GroupSelectionView(selectedUsers));
})
: null,
backgroundColor: Theme.of(context).canvasColor,
@@ -91,12 +98,14 @@ class FriendsSelectionView extends StatelessWidget {
backgroundColor: accentColor,
child: Icon(Icons.group_outlined),
),
title: Text('Create group', style: TextStyle(fontWeight: FontWeight.w700)),
title: Text('Create group',
style: TextStyle(fontWeight: FontWeight.w700)),
subtitle: Text('Talk with 2 or more contacts'),
)
else if (isGroup && selectedUsers.isEmpty)
Padding(
padding: const EdgeInsets.only(top: 15.0, left: 20.0, bottom: 20),
padding: const EdgeInsets.only(
top: 15.0, left: 20.0, bottom: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -123,7 +132,8 @@ class FriendsSelectionView extends StatelessWidget {
itemBuilder: (context, index) {
final chatUserState = selectedUsers[index];
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 13.0),
padding: const EdgeInsets.symmetric(
horizontal: 13.0),
child: Stack(
clipBehavior: Clip.none,
children: [
@@ -132,7 +142,8 @@ class FriendsSelectionView extends StatelessWidget {
children: [
CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(chatUserState.chatUser.image),
backgroundImage: NetworkImage(
chatUserState.chatUser.image),
),
Text(chatUserState.chatUser.name),
],
@@ -141,11 +152,14 @@ class FriendsSelectionView extends StatelessWidget {
bottom: 40,
right: -4,
child: InkWell(
onTap: () => context.read<FriendsSelectionCubit>().selectUser(chatUserState),
onTap: () => context
.read<FriendsSelectionCubit>()
.selectUser(chatUserState),
child: CircleAvatar(
radius: 9,
backgroundColor: accentColor,
child: Icon(Icons.close_rounded, size: 12),
child: Icon(Icons.close_rounded,
size: 12),
),
),
),
@@ -163,7 +177,8 @@ class FriendsSelectionView extends StatelessWidget {
_createFriendChannel(context, chatUserState);
},
leading: CircleAvatar(
backgroundImage: NetworkImage(chatUserState.chatUser.image),
backgroundImage:
NetworkImage(chatUserState.chatUser.image),
),
title: Text(chatUserState.chatUser.name),
trailing: isGroup
@@ -171,7 +186,9 @@ class FriendsSelectionView extends StatelessWidget {
value: chatUserState.selected,
onChanged: (val) {
print('select user for group');
context.read<FriendsSelectionCubit>().selectUser(chatUserState);
context
.read<FriendsSelectionCubit>()
.selectUser(chatUserState);
},
)
: null,
@@ -21,7 +21,8 @@ class GroupSelectionView extends StatelessWidget {
context.read(),
context.read(),
),
child: BlocConsumer<GroupSelectionCubit, GroupSelectionState>(listener: (context, snapshot) {
child: BlocConsumer<GroupSelectionCubit, GroupSelectionState>(
listener: (context, snapshot) {
if (snapshot.channel != null) {
pushAndReplaceToPage(
context,
@@ -76,9 +77,12 @@ class GroupSelectionView extends StatelessWidget {
vertical: 20,
),
child: TextField(
controller: context.read<GroupSelectionCubit>().nameTextController,
controller:
context.read<GroupSelectionCubit>().nameTextController,
decoration: InputDecoration(
fillColor: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
fillColor: Theme.of(context)
.bottomNavigationBarTheme
.backgroundColor,
hintText: 'Name of the group',
hintStyle: TextStyle(
fontSize: 13,
@@ -99,7 +103,8 @@ class GroupSelectionView extends StatelessWidget {
children: [
CircleAvatar(
radius: 30,
backgroundImage: NetworkImage(chatUserState.chatUser.image),
backgroundImage:
NetworkImage(chatUserState.chatUser.image),
),
Text(chatUserState.chatUser.name),
],
+7 -3
View File
@@ -61,7 +61,9 @@ class HomeNavigationBar extends StatelessWidget {
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
color: Theme.of(context)
.bottomNavigationBarTheme
.backgroundColor,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
@@ -122,8 +124,10 @@ class _HomeNavItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final selectedColor = Theme.of(context).bottomNavigationBarTheme.selectedItemColor;
final unselectedColor = Theme.of(context).bottomNavigationBarTheme.unselectedItemColor;
final selectedColor =
Theme.of(context).bottomNavigationBarTheme.selectedItemColor;
final unselectedColor =
Theme.of(context).bottomNavigationBarTheme.unselectedItemColor;
final color = selected ? selectedColor : unselectedColor;
return GestureDetector(
onTap: onTap,
@@ -16,7 +16,8 @@ class SettingsView extends StatelessWidget {
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => SettingsSwitchCubit(context.read<AppThemeCubit>().isDark),
create: (_) =>
SettingsSwitchCubit(context.read<AppThemeCubit>().isDark),
),
BlocProvider(
create: (_) => SettingsLogoutCubit(context.read()),
@@ -75,11 +76,14 @@ class SettingsView extends StatelessWidget {
),
),
Spacer(),
BlocBuilder<SettingsSwitchCubit, bool>(builder: (context, snapshot) {
BlocBuilder<SettingsSwitchCubit, bool>(
builder: (context, snapshot) {
return Switch(
value: snapshot,
onChanged: (val) {
context.read<SettingsSwitchCubit>().onChangeDarkMode(val);
context
.read<SettingsSwitchCubit>()
.onChangeDarkMode(val);
context.read<AppThemeCubit>().updateTheme(val);
},
);