Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2020-12-30 14:50:13 +05:30
parent 1419027acd
commit 4e7fb6123c
4 changed files with 225 additions and 226 deletions
+1 -3
View File
@@ -90,9 +90,7 @@ class _ChannelFileDisplayScreenState extends State<ChannelFileDisplayScreen> {
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.data == null) { if (snapshot.data == null) {
return Center( return Center(
child: CircularProgressIndicator( child: const CircularProgressIndicator(),
backgroundColor: StreamChatTheme.of(context).accentColor,
),
); );
} }
+8 -3
View File
@@ -75,6 +75,7 @@ class ChannelListView extends StatefulWidget {
this.swipeToAction = false, this.swipeToAction = false,
this.pullToRefresh = true, this.pullToRefresh = true,
this.crossAxisCount = 1, this.crossAxisCount = 1,
this.padding,
this.selectedChannels = const [], this.selectedChannels = const [],
}) : super(key: key); }) : super(key: key);
@@ -139,6 +140,9 @@ class ChannelListView extends StatefulWidget {
/// The number of children in the cross axis. /// The number of children in the cross axis.
final int crossAxisCount; final int crossAxisCount;
/// The amount of space by which to inset the children.
final EdgeInsetsGeometry padding;
final List<Channel> selectedChannels; final List<Channel> selectedChannels;
@override @override
@@ -268,6 +272,7 @@ class _ChannelListViewState extends State<ChannelListView>
if (channels.isNotEmpty) { if (channels.isNotEmpty) {
if (widget.crossAxisCount > 1) { if (widget.crossAxisCount > 1) {
child = GridView.builder( child = GridView.builder(
padding: widget.padding,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: widget.crossAxisCount), crossAxisCount: widget.crossAxisCount),
itemCount: channels.length, itemCount: channels.length,
@@ -279,6 +284,7 @@ class _ChannelListViewState extends State<ChannelListView>
); );
} else { } else {
child = ListView.separated( child = ListView.separated(
padding: widget.padding,
physics: AlwaysScrollableScrollPhysics(), physics: AlwaysScrollableScrollPhysics(),
itemCount: itemCount:
channels.isNotEmpty ? channels.length + 1 : channels.length, channels.isNotEmpty ? channels.length + 1 : channels.length,
@@ -306,6 +312,7 @@ class _ChannelListViewState extends State<ChannelListView>
Widget _buildLoadingWidget() { Widget _buildLoadingWidget() {
return ListView( return ListView(
padding: widget.padding,
physics: AlwaysScrollableScrollPhysics(), physics: AlwaysScrollableScrollPhysics(),
children: List.generate( children: List.generate(
25, 25,
@@ -331,9 +338,7 @@ class _ChannelListViewState extends State<ChannelListView>
highlightColor: Color(0xffffffff), highlightColor: Color(0xffffffff),
child: Column( child: Column(
children: [ children: [
SizedBox( SizedBox(height: 4.0),
height: 4.0,
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
+1 -3
View File
@@ -92,9 +92,7 @@ class _ChannelMediaDisplayScreenState extends State<ChannelMediaDisplayScreen> {
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.data == null) { if (snapshot.data == null) {
return Center( return Center(
child: CircularProgressIndicator( child: const CircularProgressIndicator(),
backgroundColor: StreamChatTheme.of(context).accentColor,
),
); );
} }
+93 -95
View File
@@ -16,7 +16,7 @@ import 'package:stream_chat_flutter/src/stream_chat.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
class ImageFooter extends StatefulWidget { class ImageFooter extends StatefulWidget implements PreferredSizeWidget {
/// Callback to call when pressing the back button. /// Callback to call when pressing the back button.
/// By default it calls [Navigator.pop] /// By default it calls [Navigator.pop]
final VoidCallback onBackPressed; final VoidCallback onBackPressed;
@@ -61,12 +61,12 @@ class ImageFooter extends StatefulWidget {
class _ImageFooterState extends State<ImageFooter> { class _ImageFooterState extends State<ImageFooter> {
bool _userSearchMode = false; bool _userSearchMode = false;
TextEditingController _searchController; TextEditingController _searchController;
TextEditingController _messageController = TextEditingController(); final TextEditingController _messageController = TextEditingController();
FocusNode _messageFocusNode = FocusNode(); final FocusNode _messageFocusNode = FocusNode();
String _channelNameQuery; String _channelNameQuery;
List<Channel> _selectedChannels = []; final List<Channel> _selectedChannels = [];
bool _loading = false; bool _loading = false;
Timer _debounce; Timer _debounce;
@@ -103,11 +103,12 @@ class _ImageFooterState extends State<ImageFooter> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SafeArea( return SizedBox.fromSize(
child: Container( size: widget.preferredSize,
color: child: MediaQuery.removePadding(
StreamChatTheme.of(context).channelTheme.channelHeaderTheme.color, context: context,
padding: EdgeInsets.symmetric(vertical: 8.0), removeTop: true,
child: BottomAppBar(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -151,6 +152,7 @@ class _ImageFooterState extends State<ImageFooter> {
], ],
), ),
), ),
),
); );
} }
@@ -258,8 +260,8 @@ class _ImageFooterState extends State<ImageFooter> {
); );
} }
void _buildShareModal(context) { void _buildShareModal(context) async {
showDialog( final result = await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return StatefulBuilder(builder: (context, modalSetState) { return StatefulBuilder(builder: (context, modalSetState) {
@@ -282,10 +284,6 @@ class _ImageFooterState extends State<ImageFooter> {
child: Column( child: Column(
children: [ children: [
_buildTextInputSection(modalSetState), _buildTextInputSection(modalSetState),
if (_userSearchMode)
SizedBox(
height: 22.0,
),
Expanded( Expanded(
child: ChannelsBloc( child: ChannelsBloc(
child: ChannelListView( child: ChannelListView(
@@ -302,6 +300,7 @@ class _ImageFooterState extends State<ImageFooter> {
}); });
} }
}, },
padding: const EdgeInsets.symmetric(vertical: 8),
crossAxisCount: 4, crossAxisCount: 4,
pagination: PaginationParams( pagination: PaginationParams(
limit: 25, limit: 25,
@@ -342,7 +341,8 @@ class _ImageFooterState extends State<ImageFooter> {
), ),
), ),
Text( Text(
'No chat matches these keywords...'), 'No chat matches these keywords...',
),
], ],
), ),
), ),
@@ -360,39 +360,29 @@ class _ImageFooterState extends State<ImageFooter> {
Align( Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: Container( child: Container(
color: Colors.white, height: kToolbarHeight,
height: 48.0, child: SizedBox.expand(
child: Material( child: RaisedButton(
child: InkWell( onPressed: () async {
onTap: () async { final attachment = widget
var url = widget .mediaAttachments[widget.currentPage];
.mediaAttachments[widget.currentPage] var url = attachment.imageUrl ??
.imageUrl ?? attachment.assetUrl ??
widget attachment.thumbUrl;
.mediaAttachments[widget.currentPage] if (attachment.type == 'video') {
.assetUrl ??
widget
.mediaAttachments[widget.currentPage]
.thumbUrl;
if (widget
.mediaAttachments[widget.currentPage]
.type ==
'video') {
await _saveVideo(url); await _saveVideo(url);
Navigator.pop(context);
} else { } else {
await _saveImage(url); await _saveImage(url);
Navigator.pop(context);
} }
Navigator.pop(context);
}, },
child: SizedBox.expand( color: Colors.white,
child: Center( elevation: 8,
child: Text( child: Text(
'Save to Photos', 'Save to Photos',
style: TextStyle( style: TextStyle(
color: StreamChatTheme.of(context) color:
.accentColor, StreamChatTheme.of(context).accentColor,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
@@ -400,8 +390,6 @@ class _ImageFooterState extends State<ImageFooter> {
), ),
), ),
), ),
),
),
], ],
), ),
), ),
@@ -411,62 +399,74 @@ class _ImageFooterState extends State<ImageFooter> {
}); });
}, },
); );
if (result == null) {
_selectedChannels.clear();
}
} }
Widget _buildTextInputSection(modalSetState) { Widget _buildTextInputSection(modalSetState) {
if (_userSearchMode) { if (_userSearchMode) {
return Column( return Column(
children: [ children: [
SizedBox( SizedBox(height: 16.0),
height: 16.0,
),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
SizedBox( SizedBox(width: 8.0),
width: 16.0,
),
Expanded( Expanded(
child: Container(
height: 36,
margin: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: TextField( child: TextField(
controller: _searchController, controller: _searchController,
cursorColor: Colors.black, cursorColor: Colors.black,
autofocus: true, autofocus: true,
decoration: InputDecoration( decoration: InputDecoration(
isDense: true, prefixIconConstraints: BoxConstraints.tight(Size(40, 24)),
prefixIconConstraints:
BoxConstraints.tight(Size(36.0, 44.0)),
prefixIcon: Padding( prefixIcon: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.only(left: 8, right: 8),
vertical: 2.0, horizontal: 6.0),
child: StreamSvgIcon.search( child: StreamSvgIcon.search(
color: Colors.black, color: Colors.black,
size: 24,
), ),
), ),
hintText: 'Search', hintText: 'Search',
border: OutlineInputBorder( hintStyle: TextStyle(
borderRadius: BorderRadius.circular(32.0), color: Colors.black.withOpacity(0.5),
borderSide: fontSize: 14,
BorderSide(color: Colors.black.withOpacity(0.08)), ),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black.withOpacity(0.08),
),
borderRadius: BorderRadius.circular(24),
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0), borderRadius: BorderRadius.circular(24.0),
borderSide: borderSide: BorderSide(
BorderSide(color: Colors.black.withOpacity(0.08)), color: Colors.black.withOpacity(0.08),
),
), ),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
), ),
), ),
), ),
SizedBox(
width: 8.0,
), ),
IconButton( IconButton(
icon: StreamSvgIcon.close_small( icon: StreamSvgIcon.close_small(
color: Colors.black.withOpacity(0.5), color: Colors.black.withOpacity(0.5),
), ),
splashRadius: 24,
onPressed: () { onPressed: () {
modalSetState(() { modalSetState(() {
if (_searchController.text.isNotEmpty) {
_searchController.text = '';
} else {
_userSearchMode = false; _userSearchMode = false;
}
}); });
setState(() {}); setState(() {});
}, },
@@ -475,7 +475,7 @@ class _ImageFooterState extends State<ImageFooter> {
), ),
], ],
); );
} else { }
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@@ -511,12 +511,11 @@ class _ImageFooterState extends State<ImageFooter> {
color: Colors.black, color: Colors.black,
), ),
onPressed: () async { onPressed: () async {
var url = final attachment = widget.mediaAttachments[widget.currentPage];
widget.mediaAttachments[widget.currentPage].imageUrl ?? var url = attachment.imageUrl ??
widget.mediaAttachments[widget.currentPage].assetUrl ?? attachment.assetUrl ??
widget.mediaAttachments[widget.currentPage].thumbUrl; attachment.thumbUrl;
var type = var type = attachment.type == 'image'
widget.mediaAttachments[widget.currentPage].type == 'image'
? 'jpg' ? 'jpg'
: url?.split('?')?.first?.split('.')?.last ?? 'jpg'; : url?.split('?')?.first?.split('.')?.last ?? 'jpg';
var request = await HttpClient().getUrl(Uri.parse(url)); var request = await HttpClient().getUrl(Uri.parse(url));
@@ -529,14 +528,17 @@ class _ImageFooterState extends State<ImageFooter> {
], ],
); );
} }
}
Widget _buildShareTextInputSection(modalSetState) { Widget _buildShareTextInputSection(modalSetState) {
return Align( return Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: BottomAppBar(
child: Container( child: Container(
color: Colors.white, height: 40.0,
height: 56.0, margin: const EdgeInsets.symmetric(
vertical: 8,
horizontal: 8,
),
child: _loading child: _loading
? Center( ? Center(
child: Padding( child: Padding(
@@ -547,8 +549,6 @@ class _ImageFooterState extends State<ImageFooter> {
: Row( : Row(
children: [ children: [
Expanded( Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: TextField( child: TextField(
controller: _messageController, controller: _messageController,
focusNode: _messageFocusNode, focusNode: _messageFocusNode,
@@ -560,43 +560,42 @@ class _ImageFooterState extends State<ImageFooter> {
setState(() {}); setState(() {});
}, },
decoration: InputDecoration( decoration: InputDecoration(
isDense: true,
prefixText: ' ', prefixText: ' ',
hintText: 'Add a comment', hintText: 'Add a comment',
border: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0), borderRadius: BorderRadius.circular(24.0),
borderSide: BorderSide( borderSide: BorderSide(
color: Colors.black.withOpacity(0.16), color: Colors.black.withOpacity(0.16),
), ),
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0), borderRadius: BorderRadius.circular(24.0),
borderSide: BorderSide( borderSide: BorderSide(
color: Colors.black.withOpacity(0.16), color: Colors.black.withOpacity(0.16),
)), )),
contentPadding: EdgeInsets.symmetric(vertical: 12.0), contentPadding: const EdgeInsets.all(0),
),
), ),
), ),
), ),
SizedBox(width: 8),
IconTheme( IconTheme(
data: StreamChatTheme.of(context) data: StreamChatTheme.of(context)
.channelTheme .channelTheme
.messageInputButtonIconTheme, .messageInputButtonIconTheme,
child: Center( child: IconButton(
child: Padding( onPressed: () async {
padding: const EdgeInsets.all(8.0), modalSetState(() => _loading = true);
child: InkWell(
onTap: () async {
modalSetState(() {
_loading = true;
});
await sendMessage(); await sendMessage();
modalSetState(() { modalSetState(() => _loading = false);
_loading = false;
});
}, },
child: Transform.rotate( splashRadius: 24,
visualDensity: VisualDensity.compact,
constraints: BoxConstraints.tightFor(
height: 24,
width: 24,
),
padding: EdgeInsets.zero,
icon: Transform.rotate(
angle: -pi / 2, angle: -pi / 2,
child: StreamSvgIcon.Icon_send_message( child: StreamSvgIcon.Icon_send_message(
color: StreamChatTheme.of(context).accentColor, color: StreamChatTheme.of(context).accentColor,
@@ -604,11 +603,10 @@ class _ImageFooterState extends State<ImageFooter> {
), ),
), ),
), ),
),
),
], ],
), ),
), ),
),
); );
} }