Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: viewer list error message #1123

Merged
merged 12 commits into from
Feb 19, 2024
78 changes: 47 additions & 31 deletions lib/components/drawer/end_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,70 @@ import 'package:rtchat/models/channels.dart';
class EndDrawerWidget extends StatefulWidget {
final Channel channel;

const EndDrawerWidget({required this.channel, super.key});
final Function(String) onError;

const EndDrawerWidget(
{required this.channel, super.key, required this.onError});

@override
State<EndDrawerWidget> createState() => EndDrawerWidgetState();
}

class EndDrawerWidgetState extends State<EndDrawerWidget> {
String _search = "";
Viewers? _viewers;

@override
void initState() {
super.initState();
_loadViewers();
}

void _loadViewers() async {
try {
final viewers = await ChatStateAdapter.instance
.getViewers(channelId: widget.channel.toString());
if (!mounted) return;
setState(() => _viewers = viewers);
SputNikPlop marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
widget.onError(e.toString());
}
}

@override
Widget build(BuildContext context) {
// Check if viewers data is available and build UI accordingly
if (_viewers == null) {
// Show loading or empty state
return const CircularProgressIndicator();
}

final filtered = _viewers!.query(_search);

return Container(
color: Theme.of(context).canvasColor,
child: FutureBuilder<Viewers>(
future: ChatStateAdapter.instance
.getViewers(channelId: widget.channel.toString()),
builder: (context, snapshot) {
final viewers = snapshot.data;
if (viewers == null) {
return const Center(child: CircularProgressIndicator());
}
final filtered = viewers.query(_search);
return SafeArea(
color: Theme.of(context).canvasColor,
child: SafeArea(
top: false,
child: CustomScrollView(
slivers: [
SliverPadding(
padding: const EdgeInsets.only(top: 24),
sliver: SliverAppBar(
actions: const [SizedBox()],
//disable the drawer icon that appears on the right of the app bar
centerTitle: false,
title: Padding(
padding: const EdgeInsets.only(left: 16),
child: Text(
AppLocalizations.of(context)!.searchViewers,
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(fontWeight: FontWeight.bold),
),
actions: const [SizedBox()],
centerTitle: false,
title: Padding(
padding: const EdgeInsets.only(left: 16),
child: Text(
AppLocalizations.of(context)!.searchViewers,
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(fontWeight: FontWeight.bold),
),
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false),
),
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
),
),
SliverSearchBarWidget(
onFilterBySearchBarText: (value) =>
Expand Down Expand Up @@ -126,10 +146,6 @@ class EndDrawerWidgetState extends State<EndDrawerWidget> {
),
],
],
),
);
},
),
);
)));
}
}
10 changes: 9 additions & 1 deletion lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
return;
}
if (context.mounted) {
model.showAudioPermissionDialog(context);

Check notice on line 174 in lib/screens/home.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check.

Guard a 'State.context' use with a 'mounted' check on the State, and other BuildContext use with a 'mounted' check on the BuildContext. See https://dart.dev/lints/use_build_context_synchronously to learn more about this problem.
}
});
}
Expand All @@ -193,7 +193,15 @@
key: _scaffoldKey,
drawer: Sidebar(channel: widget.channel),
endDrawer: userModel.isSignedIn()
? EndDrawerWidget(channel: widget.channel)
? EndDrawerWidget(
channel: widget.channel,
onError: (errorMessage) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Error: $errorMessage'),
duration: const Duration(seconds: 5),
));
},
)
: null,
drawerEdgeDragWidth: MediaQuery.of(context).size.width * 0.6,
onDrawerChanged: (isOpened) =>
Expand Down
Loading