pull refresh on session screen
This commit is contained in:
@@ -267,6 +267,33 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleRefresh() async {
|
||||
if (widget.sessionService == null) return;
|
||||
|
||||
try {
|
||||
await widget.sessionService!.refreshNostrProfile();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Session data refreshed'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to refresh: ${e.toString().replaceAll('SessionException: ', '')}'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isLoggedIn = widget.sessionService?.isLoggedIn ?? false;
|
||||
@@ -278,11 +305,20 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
: _buildRefreshableContent(isLoggedIn, currentUser),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRefreshableContent(bool isLoggedIn, currentUser) {
|
||||
final canRefresh = isLoggedIn &&
|
||||
(currentUser?.nostrProfile != null || currentUser?.nostrPrivateKey != null);
|
||||
|
||||
final content = SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (isLoggedIn && currentUser != null) ...[
|
||||
Card(
|
||||
child: Padding(
|
||||
@@ -613,9 +649,17 @@ class _SessionScreenState extends State<SessionScreen> {
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
|
||||
if (canRefresh) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _handleRefresh,
|
||||
child: content,
|
||||
);
|
||||
} else {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user