57 lines
1.9 KiB
Dart
57 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../core/network/connectivity_controller.dart';
|
|
import '../../core/theme/app_colors.dart';
|
|
import '../../l10n/app_strings.dart';
|
|
|
|
/// Compact strip shown under chrome when the device reports no connectivity.
|
|
/// Stays visible for the whole offline period; collapses when back online.
|
|
class OfflineBanner extends StatelessWidget {
|
|
const OfflineBanner({
|
|
super.key,
|
|
required this.controller,
|
|
this.includeStatusBarPadding = false,
|
|
});
|
|
|
|
final ConnectivityController controller;
|
|
|
|
/// When true (AppShell), pads below the status bar so the strip is readable
|
|
/// when the shell no longer applies a top [SafeArea].
|
|
final bool includeStatusBarPadding;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, _) {
|
|
if (controller.isOnline) return const SizedBox.shrink();
|
|
final s = context.strings;
|
|
final topInset =
|
|
includeStatusBarPadding ? MediaQuery.paddingOf(context).top : 0.0;
|
|
return Material(
|
|
key: const Key('offline_banner'),
|
|
color: AppColors.warning.withValues(alpha: 0.22),
|
|
child: Padding(
|
|
padding: EdgeInsets.fromLTRB(14, 10 + topInset, 14, 10),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.cloud_off_rounded, size: 20, color: AppColors.warning),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
s.offlineBanner,
|
|
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
|
color: AppColors.warning,
|
|
fontWeight: FontWeight.w800,
|
|
height: 1.25,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|