action snack bar layout review
This commit is contained in:
parent
08daddb1ec
commit
6dc2d81027
2 changed files with 21 additions and 14 deletions
|
@ -39,9 +39,12 @@ mixin FeedbackMixin {
|
|||
void showFeedbackWithMessenger(BuildContext context, ScaffoldMessengerState messenger, String message, [SnackBarAction? action]) {
|
||||
_getSnackBarDuration(action != null).then((duration) {
|
||||
final start = DateTime.now();
|
||||
final theme = Theme.of(context);
|
||||
final snackBarTheme = theme.snackBarTheme;
|
||||
|
||||
final snackBarContent = _FeedbackMessage(
|
||||
message: message,
|
||||
progressColor: Theme.of(context).colorScheme.secondary,
|
||||
progressColor: theme.colorScheme.secondary,
|
||||
start: start,
|
||||
stop: action != null ? start.add(duration) : null,
|
||||
);
|
||||
|
@ -64,7 +67,7 @@ mixin FeedbackMixin {
|
|||
action: action != null
|
||||
? TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(Theme.of(context).snackBarTheme.actionTextColor),
|
||||
foregroundColor: MaterialStateProperty.all(snackBarTheme.actionTextColor),
|
||||
),
|
||||
onPressed: () {
|
||||
notificationOverlayEntry?.dismiss();
|
||||
|
@ -87,6 +90,7 @@ mixin FeedbackMixin {
|
|||
} else {
|
||||
messenger.showSnackBar(SnackBar(
|
||||
content: snackBarContent,
|
||||
padding: action != null ? EdgeInsetsDirectional.only(start: snackBarHorizontalPadding(snackBarTheme)) : null,
|
||||
action: action,
|
||||
duration: duration,
|
||||
dismissDirection: DismissDirection.horizontal,
|
||||
|
@ -95,6 +99,12 @@ mixin FeedbackMixin {
|
|||
});
|
||||
}
|
||||
|
||||
static double snackBarHorizontalPadding(SnackBarThemeData snackBarTheme) {
|
||||
final isFloatingSnackBar = (snackBarTheme.behavior ?? SnackBarBehavior.fixed) == SnackBarBehavior.floating;
|
||||
final horizontalPadding = isFloatingSnackBar ? 16.0 : 24.0;
|
||||
return horizontalPadding;
|
||||
}
|
||||
|
||||
Future<Duration> _getSnackBarDuration(bool hasAction) async {
|
||||
final appDefaultDuration = hasAction ? Durations.opToastActionDisplay : Durations.opToastTextDisplay;
|
||||
switch (settings.timeToTakeAction) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// adapted from Flutter `SnackBar` in `/material/snack_bar.dart`
|
||||
|
@ -49,9 +50,8 @@ class OverlaySnackBar extends StatelessWidget {
|
|||
|
||||
final contentTextStyle = snackBarTheme.contentTextStyle ?? ThemeData(brightness: brightness).textTheme.subtitle1;
|
||||
|
||||
const horizontalPadding = 16.0;
|
||||
final horizontalPadding = FeedbackMixin.snackBarHorizontalPadding(snackBarTheme);
|
||||
final padding = EdgeInsetsDirectional.only(start: horizontalPadding, end: action != null ? 0 : horizontalPadding);
|
||||
const actionHorizontalMargin = horizontalPadding / 2;
|
||||
const singleLineVerticalPadding = 14.0;
|
||||
|
||||
Widget snackBar = Padding(
|
||||
|
@ -60,7 +60,7 @@ class OverlaySnackBar extends StatelessWidget {
|
|||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: singleLineVerticalPadding),
|
||||
padding: action != null ? null : const EdgeInsets.symmetric(vertical: singleLineVerticalPadding),
|
||||
child: DefaultTextStyle(
|
||||
style: contentTextStyle!,
|
||||
child: content,
|
||||
|
@ -68,17 +68,14 @@ class OverlaySnackBar extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
if (action != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: actionHorizontalMargin),
|
||||
child: TextButtonTheme(
|
||||
data: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: buttonColor,
|
||||
padding: const EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
),
|
||||
TextButtonTheme(
|
||||
data: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: buttonColor,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
),
|
||||
child: action!,
|
||||
),
|
||||
child: action!,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue