-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cat-voices): Add "No Internet Connection Banner" widget (#827)
* feat: initial widget * feat: register widget * fix: layout * feat: expand banner * feat: button display on wide screen * refactor: using theme * refactor: theme color on white * refactor: var name * fix: warnings * fix: warnings * feat: i10n * fix: example removing row * fix: margin * refactor: remove noop * docs: widget * refactor: removing single child col * feat: theme colors * fix: localization --------- Co-authored-by: Dominik Toton <[email protected]>
- Loading branch information
Showing
7 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
catalyst_voices/lib/widgets/indicators/voices_no_internet_connection_banner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:catalyst_voices/widgets/widgets.dart'; | ||
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; | ||
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; | ||
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// A banner that indicates a lack of internet connection. | ||
/// | ||
/// Includes a refresh button, which is displayed only on desktop-sized screens. | ||
/// The [onRefresh] callback is triggered when the refresh button is pressed. | ||
/// If no [onRefresh] callback is provided, the button will appear disabled. | ||
/// | ||
/// The banner is only visible when there is no internet connection and is | ||
/// typically used in scenarios where users need to be alerted to connectivity | ||
/// issues. | ||
/// | ||
/// **Example Usage:** | ||
/// ```dart | ||
/// NoInternetConnectionBanner( | ||
/// onRefresh: () { | ||
/// // Handle refresh logic here | ||
/// }, | ||
/// ) | ||
/// ``` | ||
class NoInternetConnectionBanner extends StatelessWidget { | ||
final VoidCallback? onRefresh; | ||
|
||
const NoInternetConnectionBanner({ | ||
super.key, | ||
this.onRefresh, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return LayoutBuilder( | ||
builder: (context, constraints) { | ||
final shouldButtonDisplay = constraints.maxWidth > 744; | ||
|
||
return Container( | ||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), | ||
margin: const EdgeInsets.all(16), | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colors.avatarsError, | ||
borderRadius: BorderRadius.circular(8), | ||
), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
CatalystSvgIcon.asset( | ||
VoicesAssets.icons.wifi.path, | ||
color: Theme.of(context).colors.iconsForeground, | ||
), | ||
const SizedBox(width: 8), | ||
Expanded( | ||
child: Text( | ||
context.l10n.noConnectionBannerTitle, | ||
style: Theme.of(context).textTheme.titleLarge, | ||
), | ||
), | ||
], | ||
), | ||
Text( | ||
context.l10n.noConnectionBannerDescription, | ||
style: Theme.of(context).textTheme.bodySmall, | ||
softWrap: true, | ||
), | ||
], | ||
), | ||
), | ||
if (shouldButtonDisplay) ...[ | ||
const SizedBox(height: 16), | ||
VoicesTextButton( | ||
onTap: onRefresh, | ||
child: Text( | ||
context.l10n.noConnectionBannerRefreshButtonText, | ||
style: Theme.of(context).textTheme.labelLarge, | ||
), | ||
), | ||
], | ||
], | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters