[NewGroupChatScreen] Refactor

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-01-06 19:07:51 +05:30
parent b51128f67c
commit 7ae15263e3
+207 -214
View File
@@ -52,234 +52,227 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: StreamChatTheme.of(context).colorTheme.whiteSnow, backgroundColor: StreamChatTheme.of(context).colorTheme.whiteSnow,
body: SafeArea( appBar: AppBar(
child: NestedScrollView( elevation: 1,
floatHeaderSlivers: true, backgroundColor: StreamChatTheme.of(context).colorTheme.white,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { leading: const StreamBackButton(),
return <Widget>[ title: Text(
SliverAppBar( 'Add Group Members',
brightness: Theme.of(context).brightness, style: TextStyle(
pinned: true, color: StreamChatTheme.of(context).colorTheme.black,
forceElevated: true, fontSize: 16,
elevation: 1, ),
backgroundColor: StreamChatTheme.of(context).colorTheme.white, ),
leading: const StreamBackButton(), centerTitle: true,
title: Text( actions: [
'Add Group Members', if (_selectedUsers.isNotEmpty)
style: TextStyle( IconButton(
color: StreamChatTheme.of(context).colorTheme.black, icon: StreamSvgIcon.arrow_right(
fontSize: 16, color: StreamChatTheme.of(context).colorTheme.accentBlue,
),
),
centerTitle: true,
actions: [
if (_selectedUsers.isNotEmpty)
IconButton(
icon: StreamSvgIcon.arrow_right(
color:
StreamChatTheme.of(context).colorTheme.accentBlue,
),
onPressed: () async {
final updatedList = await Navigator.pushNamed(
context,
Routes.NEW_GROUP_CHAT_DETAILS,
arguments: _selectedUsers.toList(growable: false),
);
if (updatedList != null) {
setState(() {
_selectedUsers
..clear()
..addAll(updatedList);
});
}
},
)
],
), ),
onPressed: () async {
final updatedList = await Navigator.pushNamed(
context,
Routes.NEW_GROUP_CHAT_DETAILS,
arguments: _selectedUsers.toList(growable: false),
);
if (updatedList != null) {
setState(() {
_selectedUsers
..clear()
..addAll(updatedList);
});
}
},
)
],
),
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverToBoxAdapter(
child: SearchTextField(
controller: _controller,
),
),
if (_selectedUsers.isNotEmpty)
SliverToBoxAdapter( SliverToBoxAdapter(
child: SearchTextField( child: Container(
controller: _controller, height: 104,
), child: ListView.separated(
), scrollDirection: Axis.horizontal,
if (_selectedUsers.isNotEmpty) itemCount: _selectedUsers.length,
SliverToBoxAdapter( padding: const EdgeInsets.all(8),
child: Container( separatorBuilder: (_, __) => SizedBox(width: 16),
height: 104, itemBuilder: (_, index) {
child: ListView.separated( final user = _selectedUsers.elementAt(index);
scrollDirection: Axis.horizontal, return Column(
itemCount: _selectedUsers.length, children: [
padding: const EdgeInsets.all(8), Stack(
separatorBuilder: (_, __) => SizedBox(width: 16), children: [
itemBuilder: (_, index) { UserAvatar(
final user = _selectedUsers.elementAt(index); onlineIndicatorAlignment: Alignment(0.9, 0.9),
return Column( user: user,
children: [ showOnlineStatus: true,
Stack( borderRadius: BorderRadius.circular(32),
children: [ constraints: BoxConstraints.tightFor(
UserAvatar( height: 64,
onlineIndicatorAlignment: Alignment(0.9, 0.9), width: 64,
user: user,
showOnlineStatus: true,
borderRadius: BorderRadius.circular(32),
constraints: BoxConstraints.tightFor(
height: 64,
width: 64,
),
), ),
Positioned( ),
top: -4, Positioned(
right: -4, top: -4,
child: GestureDetector( right: -4,
onTap: () { child: GestureDetector(
if (_selectedUsers.contains(user)) { onTap: () {
setState( if (_selectedUsers.contains(user)) {
() => _selectedUsers.remove(user)); setState(
} () => _selectedUsers.remove(user));
}, }
child: Container( },
decoration: BoxDecoration( child: Container(
decoration: BoxDecoration(
color: StreamChatTheme.of(context)
.colorTheme
.white,
shape: BoxShape.circle,
border: Border.all(
color: StreamChatTheme.of(context) color: StreamChatTheme.of(context)
.colorTheme .colorTheme
.white, .whiteSnow,
shape: BoxShape.circle,
border: Border.all(
color: StreamChatTheme.of(context)
.colorTheme
.whiteSnow,
),
),
child: StreamSvgIcon.close(
color: StreamChatTheme.of(context)
.colorTheme
.black,
size: 24,
), ),
), ),
), child: StreamSvgIcon.close(
) color: StreamChatTheme.of(context)
], .colorTheme
), .black,
SizedBox(height: 4), size: 24,
Text( ),
user.name.split(' ')[0],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
],
);
},
),
),
),
SliverPersistentHeader(
pinned: true,
delegate: _HeaderDelegate(
height: 30,
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient:
StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? 'Matches for \"$_userNameQuery\"'
: 'On the platform',
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.grey,
),
),
),
),
),
),
];
},
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) => FocusScope.of(context).unfocus(),
child: UsersBloc(
child: UserListView(
selectedUsers: _selectedUsers,
pullToRefresh: false,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
setState(() {
_selectedUsers.add(user);
});
} else {
setState(() {
_selectedUsers.remove(user);
});
}
},
pagination: PaginationParams(
limit: 25,
),
filter: {
if (_userNameQuery.isNotEmpty)
'name': {
r'$autocomplete': _userNameQuery,
},
'id': {
r'$ne': StreamChat.of(context).user.id,
}
},
sort: [
SortOption(
'name',
direction: 1,
),
],
emptyBuilder: (_) {
return LayoutBuilder(
builder: (context, viewportConstraints) {
return SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(24),
child: StreamSvgIcon.search(
size: 96,
color: StreamChatTheme.of(context)
.colorTheme
.grey,
), ),
), ),
Text( )
'No user matches these keywords...', ],
style: StreamChatTheme.of(context) ),
.textTheme SizedBox(height: 4),
.footnote Text(
.copyWith( user.name.split(' ')[0],
color: StreamChatTheme.of(context) style: TextStyle(
.colorTheme fontWeight: FontWeight.bold,
.grey, fontSize: 12,
),
),
],
), ),
), ),
), ],
); );
}, },
); ),
}, ),
), ),
SliverPersistentHeader(
pinned: true,
delegate: _HeaderDelegate(
height: 30,
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
gradient: StreamChatTheme.of(context).colorTheme.bgGradient,
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: Text(
_isSearchActive
? 'Matches for \"$_userNameQuery\"'
: 'On the platform',
style: TextStyle(
color: StreamChatTheme.of(context).colorTheme.grey,
),
),
),
),
),
),
];
},
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanDown: (_) => FocusScope.of(context).unfocus(),
child: UsersBloc(
child: UserListView(
selectedUsers: _selectedUsers,
pullToRefresh: false,
groupAlphabetically: _isSearchActive ? false : true,
onUserTap: (user, _) {
if (!_selectedUsers.contains(user)) {
setState(() {
_selectedUsers.add(user);
});
} else {
setState(() {
_selectedUsers.remove(user);
});
}
},
pagination: PaginationParams(
limit: 25,
),
filter: {
if (_userNameQuery.isNotEmpty)
'name': {
r'$autocomplete': _userNameQuery,
},
'id': {
r'$ne': StreamChat.of(context).user.id,
}
},
sort: [
SortOption(
'name',
direction: 1,
),
],
emptyBuilder: (_) {
return LayoutBuilder(
builder: (context, viewportConstraints) {
return SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(24),
child: StreamSvgIcon.search(
size: 96,
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
Text(
'No user matches these keywords...',
style: StreamChatTheme.of(context)
.textTheme
.footnote
.copyWith(
color: StreamChatTheme.of(context)
.colorTheme
.grey,
),
),
],
),
),
),
);
},
);
},
), ),
), ),
), ),