feat(#1258): region-scope banner on the channel chat
A bar at the top of a region-scoped channel reminds the user which region its messages ride and opens Set Region Scope on tap. Dismissible for the session (in-memory, keyed by channel PSK), returns on a fresh app open. Service + widget tests; the nav test gains the new provider.pull/1263/head
parent
28b7f36c69
commit
2e5930f5b0
@ -0,0 +1,15 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Tracks which region-scoped channels have had their banner dismissed, for the
|
||||
/// current app session only. Keyed by channel PSK hex, held in memory, so a
|
||||
/// dismissal lasts until the app is closed and the banner returns on a fresh
|
||||
/// open (#1258). Not persisted.
|
||||
class RegionScopeBannerService extends ChangeNotifier {
|
||||
final Set<String> _dismissed = {};
|
||||
|
||||
bool isDismissed(String channelPskHex) => _dismissed.contains(channelPskHex);
|
||||
|
||||
void dismiss(String channelPskHex) {
|
||||
if (_dismissed.add(channelPskHex)) notifyListeners();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
|
||||
/// A banner at the top of a region-scoped channel chat reminding the user that
|
||||
/// the channel's messages ride a region. Tapping it opens Set Region Scope so
|
||||
/// the user can change or clear the scope; the close button dismisses it for the
|
||||
/// session. Renders nothing when [regionName] is null (unscoped or dismissed).
|
||||
/// (#1258)
|
||||
class RegionScopeBanner extends StatelessWidget {
|
||||
const RegionScopeBanner({
|
||||
super.key,
|
||||
required this.regionName,
|
||||
required this.onTap,
|
||||
required this.onDismiss,
|
||||
});
|
||||
|
||||
final String? regionName;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onDismiss;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final name = regionName;
|
||||
if (name == null) return const SizedBox.shrink();
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Material(
|
||||
color: scheme.secondaryContainer,
|
||||
child: InkWell(
|
||||
key: const Key('regionScopeBannerBody'),
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 8, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.travel_explore,
|
||||
size: 20,
|
||||
color: scheme.onSecondaryContainer,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.setRegionScope_banner(name),
|
||||
style: TextStyle(color: scheme.onSecondaryContainer),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('regionScopeBannerDismiss'),
|
||||
icon: const Icon(Icons.close, size: 20),
|
||||
color: scheme.onSecondaryContainer,
|
||||
tooltip: l10n.setRegionScope_bannerDismiss,
|
||||
onPressed: onDismiss,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
// Per-session dismissal of the region-scope banner, keyed by channel PSK (#1258).
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/services/region_scope_banner_service.dart';
|
||||
|
||||
void main() {
|
||||
test('a channel banner is not dismissed until dismissed', () {
|
||||
final s = RegionScopeBannerService();
|
||||
expect(s.isDismissed('pska'), isFalse);
|
||||
s.dismiss('pska');
|
||||
expect(s.isDismissed('pska'), isTrue);
|
||||
expect(s.isDismissed('pskb'), isFalse); // other channels unaffected
|
||||
});
|
||||
|
||||
test('dismiss notifies listeners so the banner can hide', () {
|
||||
final s = RegionScopeBannerService();
|
||||
var notified = 0;
|
||||
s.addListener(() => notified++);
|
||||
s.dismiss('pska');
|
||||
expect(notified, 1);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
// Region-scope banner on the channel chat (#1258).
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/widgets/region_scope_banner.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> pump(
|
||||
WidgetTester tester, {
|
||||
required String? regionName,
|
||||
VoidCallback? onTap,
|
||||
VoidCallback? onDismiss,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: RegionScopeBanner(
|
||||
regionName: regionName,
|
||||
onTap: onTap ?? () {},
|
||||
onDismiss: onDismiss ?? () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('shows the scoped region name', (tester) async {
|
||||
await pump(tester, regionName: 'cvg');
|
||||
expect(find.textContaining('cvg'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('tapping the banner opens Set Region Scope (onTap)', (
|
||||
tester,
|
||||
) async {
|
||||
var taps = 0;
|
||||
await pump(tester, regionName: 'cvg', onTap: () => taps++);
|
||||
await tester.tap(find.byKey(const Key('regionScopeBannerBody')));
|
||||
expect(taps, 1);
|
||||
});
|
||||
|
||||
testWidgets('tapping dismiss fires onDismiss', (tester) async {
|
||||
var dismissed = 0;
|
||||
await pump(tester, regionName: 'cvg', onDismiss: () => dismissed++);
|
||||
await tester.tap(find.byKey(const Key('regionScopeBannerDismiss')));
|
||||
expect(dismissed, 1);
|
||||
});
|
||||
|
||||
testWidgets('renders nothing when the channel is not scoped', (tester) async {
|
||||
await pump(tester, regionName: null);
|
||||
expect(find.byKey(const Key('regionScopeBannerBody')), findsNothing);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue