Improve repo structure (#22)
* app updated * readme updated * rename base folder * update chatty's readme * move apps to packages dir * update repo overview Co-authored-by: diegoveloper <[email protected]>
This commit is contained in:
co-authored by
diegoveloper
parent
bd6bb66279
commit
030c3eb428
@@ -0,0 +1,160 @@
|
||||
import 'package:stream_chatter/ui/common/my_channel_preview.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class ChatView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textColor = Theme.of(context).appBarTheme.color;
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'Chats',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
),
|
||||
body: ChannelsBloc(
|
||||
child: ChannelListView(
|
||||
filter: {
|
||||
'members': {
|
||||
'\$in': [StreamChat.of(context).user?.id],
|
||||
}
|
||||
},
|
||||
sort: [SortOption('last_message_at')],
|
||||
channelPreviewBuilder: (context, channel) {
|
||||
return Container(
|
||||
color: Theme.of(context).canvasColor,
|
||||
child: MyChannelPreview(
|
||||
channel: channel,
|
||||
heroTag: channel.id,
|
||||
onImageTap: () {
|
||||
String name;
|
||||
String image;
|
||||
final currentUser = StreamChat.of(context).client.state.user;
|
||||
if (channel.isGroup) {
|
||||
name = channel.extraData['name'];
|
||||
image = channel.extraData['image'];
|
||||
} else {
|
||||
final friend =
|
||||
channel.state.members.where((element) => element.userId != currentUser.id).first.user;
|
||||
name = friend.name;
|
||||
image = friend.extraData['image'];
|
||||
}
|
||||
|
||||
return Navigator.of(context).push(
|
||||
PageRouteBuilder(
|
||||
barrierColor: Colors.black45,
|
||||
barrierDismissible: true,
|
||||
opaque: false,
|
||||
pageBuilder: (context, animation1, _) {
|
||||
return FadeTransition(
|
||||
opacity: animation1,
|
||||
child: ChatDetailView(
|
||||
channelId: channel.id,
|
||||
image: image,
|
||||
name: name,
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
onTap: (channel) => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return StreamChannel(
|
||||
child: ChannelPage(),
|
||||
channel: channel,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
channelWidget: ChannelPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChannelPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: ChannelHeader(),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MessageListView(),
|
||||
),
|
||||
MessageInput(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChatDetailView extends StatelessWidget {
|
||||
const ChatDetailView({
|
||||
Key key,
|
||||
this.image,
|
||||
this.name,
|
||||
this.channelId,
|
||||
}) : super(key: key);
|
||||
|
||||
final String image;
|
||||
final String name;
|
||||
final String channelId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: Navigator.of(context).pop,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Hero(
|
||||
tag: channelId,
|
||||
child: ClipOval(
|
||||
child: Image.network(
|
||||
image,
|
||||
height: 180,
|
||||
width: 180,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 22,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:stream_chatter/data/stream_api_repository.dart';
|
||||
import 'package:stream_chatter/domain/models/chat_user.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class ChatUserState {
|
||||
const ChatUserState(this.chatUser, {this.selected = false});
|
||||
final ChatUser chatUser;
|
||||
final bool selected;
|
||||
}
|
||||
|
||||
class FriendsSelectionCubit extends Cubit<List<ChatUserState>> {
|
||||
FriendsSelectionCubit(this._streamApiRepository) : super([]);
|
||||
final StreamApiRepository _streamApiRepository;
|
||||
|
||||
List<ChatUserState> get selectedUsers => state.where((element) => element.selected).toList();
|
||||
|
||||
Future<void> init() async {
|
||||
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);
|
||||
emit(List<ChatUserState>.from(state));
|
||||
}
|
||||
|
||||
Future<Channel> createFriendChannel(ChatUserState chatUserState) async {
|
||||
return await _streamApiRepository.createSimpleChat(chatUserState.chatUser.id);
|
||||
}
|
||||
}
|
||||
|
||||
class FriendsGroupCubit extends Cubit<bool> {
|
||||
FriendsGroupCubit() : super(false);
|
||||
|
||||
void changeToGroup() => emit(!state);
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/chat_view.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/friends_selection_cubit.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/group_selection_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
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);
|
||||
pushAndReplaceToPage(
|
||||
context,
|
||||
Scaffold(
|
||||
body: StreamChannel(
|
||||
channel: channel,
|
||||
child: ChannelPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textColor = Theme.of(context).appBarTheme.color;
|
||||
final accentColor = Theme.of(context).accentColor;
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
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 Scaffold(
|
||||
floatingActionButton: isGroup && selectedUsers.isNotEmpty
|
||||
? FloatingActionButton(
|
||||
child: Icon(Icons.arrow_right_alt_rounded),
|
||||
onPressed: () {
|
||||
pushAndReplaceToPage(context, GroupSelectionView(selectedUsers));
|
||||
})
|
||||
: null,
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10.0,
|
||||
vertical: 20,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (isGroup)
|
||||
Row(
|
||||
children: [
|
||||
BackButton(
|
||||
onPressed: () {
|
||||
context.read<FriendsGroupCubit>().changeToGroup();
|
||||
},
|
||||
),
|
||||
Text(
|
||||
'New Group',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Row(
|
||||
children: [
|
||||
BackButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
),
|
||||
Text(
|
||||
'People',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!isGroup)
|
||||
ListTile(
|
||||
onTap: context.read<FriendsGroupCubit>().changeToGroup,
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: accentColor,
|
||||
child: Icon(Icons.group_outlined),
|
||||
),
|
||||
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),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors.grey[200],
|
||||
),
|
||||
Text(
|
||||
'Add a friend',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: 100,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: selectedUsers.length,
|
||||
itemBuilder: (context, index) {
|
||||
final chatUserState = selectedUsers[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 13.0),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundImage: NetworkImage(chatUserState.chatUser.image),
|
||||
),
|
||||
Text(chatUserState.chatUser.name),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
bottom: 40,
|
||||
right: -4,
|
||||
child: InkWell(
|
||||
onTap: () => context.read<FriendsSelectionCubit>().selectUser(chatUserState),
|
||||
child: CircleAvatar(
|
||||
radius: 9,
|
||||
backgroundColor: accentColor,
|
||||
child: Icon(Icons.close_rounded, size: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
})),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: snapshot.length,
|
||||
itemBuilder: (context, index) {
|
||||
final chatUserState = snapshot[index];
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
_createFriendChannel(context, chatUserState);
|
||||
},
|
||||
leading: CircleAvatar(
|
||||
backgroundImage: NetworkImage(chatUserState.chatUser.image),
|
||||
),
|
||||
title: Text(chatUserState.chatUser.name),
|
||||
trailing: isGroup
|
||||
? Checkbox(
|
||||
value: chatUserState.selected,
|
||||
onChanged: (val) {
|
||||
print('select user for group');
|
||||
context.read<FriendsSelectionCubit>().selectUser(chatUserState);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:stream_chatter/data/image_picker_repository.dart';
|
||||
import 'package:stream_chatter/domain/usecases/create_group_usecase.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/friends_selection_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class GroupSelectionState {
|
||||
const GroupSelectionState(
|
||||
this.file, {
|
||||
this.channel,
|
||||
this.isLoading = false,
|
||||
});
|
||||
final File file;
|
||||
final Channel channel;
|
||||
final bool isLoading;
|
||||
}
|
||||
|
||||
class GroupSelectionCubit extends Cubit<GroupSelectionState> {
|
||||
GroupSelectionCubit(
|
||||
this.members,
|
||||
this._createGroupUseCase,
|
||||
this._imagePickerRepository,
|
||||
) : super(GroupSelectionState(null));
|
||||
|
||||
final nameTextController = TextEditingController();
|
||||
final List<ChatUserState> members;
|
||||
final CreateGroupUseCase _createGroupUseCase;
|
||||
final ImagePickerRepository _imagePickerRepository;
|
||||
|
||||
void createGroup() async {
|
||||
emit(GroupSelectionState(state.file, isLoading: true));
|
||||
final channel = await _createGroupUseCase.createGroup(CreateGroupInput(
|
||||
imageFile: state.file,
|
||||
members: members.map((e) => e.chatUser.id).toList(),
|
||||
name: nameTextController.text,
|
||||
));
|
||||
emit(GroupSelectionState(state.file, channel: channel, isLoading: false));
|
||||
}
|
||||
|
||||
void pickImage() async {
|
||||
final image = await _imagePickerRepository.pickImage();
|
||||
emit(GroupSelectionState(image));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/common/avatar_image_view.dart';
|
||||
import 'package:stream_chatter/ui/common/loading_view.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/chat_view.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/friends_selection_cubit.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/group_selection_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class GroupSelectionView extends StatelessWidget {
|
||||
GroupSelectionView(this.selectedUsers);
|
||||
|
||||
final List<ChatUserState> selectedUsers;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => GroupSelectionCubit(
|
||||
selectedUsers,
|
||||
context.read(),
|
||||
context.read(),
|
||||
),
|
||||
child: BlocConsumer<GroupSelectionCubit, GroupSelectionState>(listener: (context, snapshot) {
|
||||
if (snapshot.channel != null) {
|
||||
pushAndReplaceToPage(
|
||||
context,
|
||||
Scaffold(
|
||||
body: StreamChannel(
|
||||
channel: snapshot.channel,
|
||||
child: ChannelPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}, builder: (context, snapshot) {
|
||||
return LoadingView(
|
||||
isLoading: snapshot.isLoading,
|
||||
child: Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.arrow_right_alt_rounded),
|
||||
onPressed: context.read<GroupSelectionCubit>().createGroup,
|
||||
),
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'New Group',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: Theme.of(context).appBarTheme.color,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
AvatarImageView(
|
||||
onTap: context.read<GroupSelectionCubit>().pickImage,
|
||||
child: snapshot?.file != null
|
||||
? Image.file(
|
||||
snapshot?.file,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Icon(
|
||||
Icons.person_outline,
|
||||
size: 100,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 50.0,
|
||||
vertical: 20,
|
||||
),
|
||||
child: TextField(
|
||||
controller: context.read<GroupSelectionCubit>().nameTextController,
|
||||
decoration: InputDecoration(
|
||||
fillColor: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
|
||||
hintText: 'Name of the group',
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
Wrap(
|
||||
children: List.generate(selectedUsers.length, (index) {
|
||||
final chatUserState = selectedUsers[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundImage: NetworkImage(chatUserState.chatUser.image),
|
||||
),
|
||||
Text(chatUserState.chatUser.name),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class HomeCubit extends Cubit<int> {
|
||||
HomeCubit() : super(0);
|
||||
|
||||
void onChangeTab(int index) => emit(index);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/chat_view.dart';
|
||||
import 'package:stream_chatter/ui/home/chat/selection/friends_selection_view.dart';
|
||||
import 'package:stream_chatter/ui/home/home_cubit.dart';
|
||||
import 'package:stream_chatter/ui/home/settings/settings_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class HomeView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
body: BlocProvider(
|
||||
create: (_) => HomeCubit(),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: BlocBuilder<HomeCubit, int>(builder: (context, snapshot) {
|
||||
return IndexedStack(
|
||||
index: snapshot,
|
||||
children: [
|
||||
ChatView(),
|
||||
SettingsView(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
HomeNavigationBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomeNavigationBar extends StatelessWidget {
|
||||
const HomeNavigationBar({
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cubit = BlocProvider.of<HomeCubit>(context, listen: true);
|
||||
final navigationBarSize = 80.0;
|
||||
final buttonSize = 56.0;
|
||||
final buttonMargin = 4.0;
|
||||
final topMargin = buttonSize / 2 + buttonMargin / 2;
|
||||
final canvasColor = Theme.of(context).canvasColor;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20.0),
|
||||
child: Material(
|
||||
child: Container(
|
||||
height: navigationBarSize + topMargin,
|
||||
width: MediaQuery.of(context).size.width * 0.7,
|
||||
color: canvasColor,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
top: topMargin,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
color: Theme.of(context).bottomNavigationBarTheme.backgroundColor,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_HomeNavItem(
|
||||
text: 'Chats',
|
||||
iconData: Icons.chat_bubble,
|
||||
onTap: () => cubit.onChangeTab(0),
|
||||
selected: cubit.state == 0,
|
||||
),
|
||||
_HomeNavItem(
|
||||
text: 'Settings',
|
||||
iconData: Icons.settings,
|
||||
onTap: () => cubit.onChangeTab(1),
|
||||
selected: cubit.state == 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: canvasColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
padding: EdgeInsets.all(buttonMargin / 2),
|
||||
child: FloatingActionButton(
|
||||
onPressed: () {
|
||||
pushToPage(context, FriendsSelectionView());
|
||||
},
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _HomeNavItem extends StatelessWidget {
|
||||
const _HomeNavItem({
|
||||
Key key,
|
||||
this.iconData,
|
||||
this.text,
|
||||
this.onTap,
|
||||
this.selected = false,
|
||||
}) : super(key: key);
|
||||
|
||||
final IconData iconData;
|
||||
final String text;
|
||||
final VoidCallback onTap;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selectedColor = Theme.of(context).bottomNavigationBarTheme.selectedItemColor;
|
||||
final unselectedColor = Theme.of(context).bottomNavigationBarTheme.unselectedItemColor;
|
||||
final color = selected ? selectedColor : unselectedColor;
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(iconData, color: color),
|
||||
Text(text, style: TextStyle(color: color)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:stream_chatter/domain/usecases/logout_usecase.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SettingsSwitchCubit extends Cubit<bool> {
|
||||
SettingsSwitchCubit(bool state) : super(state);
|
||||
|
||||
void onChangeDarkMode(bool isDark) => emit(isDark);
|
||||
}
|
||||
|
||||
class SettingsLogoutCubit extends Cubit<void> {
|
||||
SettingsLogoutCubit(this._logoutUseCase) : super(null);
|
||||
|
||||
final LogoutUseCase _logoutUseCase;
|
||||
|
||||
void logOut() async {
|
||||
await _logoutUseCase.logout();
|
||||
emit(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/app_theme_cubit.dart';
|
||||
import 'package:stream_chatter/ui/common/avatar_image_view.dart';
|
||||
import 'package:stream_chatter/ui/home/settings/settings_cubit.dart';
|
||||
import 'package:stream_chatter/ui/sign_in/sign_in_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class SettingsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = StreamChat.of(context).client.state.user;
|
||||
final image = user?.extraData['image'];
|
||||
final textColor = Theme.of(context).appBarTheme.color;
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (_) => SettingsSwitchCubit(context.read<AppThemeCubit>().isDark),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (_) => SettingsLogoutCubit(context.read()),
|
||||
),
|
||||
],
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'Settings',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Column(
|
||||
children: [
|
||||
AvatarImageView(
|
||||
//TODO: implement change avatar
|
||||
onTap: () => null,
|
||||
child: image != null
|
||||
? Image.network(
|
||||
image,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Icon(
|
||||
Icons.person_outline,
|
||||
size: 100,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
user.name,
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.nights_stay_outlined),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Dark Mode',
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
BlocBuilder<SettingsSwitchCubit, bool>(builder: (context, snapshot) {
|
||||
return Switch(
|
||||
value: snapshot,
|
||||
onChanged: (val) {
|
||||
context.read<SettingsSwitchCubit>().onChangeDarkMode(val);
|
||||
context.read<AppThemeCubit>().updateTheme(val);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Builder(builder: (context) {
|
||||
return GestureDetector(
|
||||
onTap: context.read<SettingsLogoutCubit>().logOut,
|
||||
child: BlocListener<SettingsLogoutCubit, void>(
|
||||
listener: (context, snapshot) {
|
||||
popAllAndPush(context, SignInView());
|
||||
},
|
||||
child: Row(children: [
|
||||
Icon(Icons.logout),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Logout',
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(Icons.arrow_right),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user