예제 #1
0
        public override Widget build(BuildContext context)
        {
            SnackBarThemeData snackBarTheme     = Theme.of(context).snackBarTheme;
            Color             textColor         = widget.textColor ?? snackBarTheme.actionTextColor;
            Color             disabledTextColor = widget.disabledTextColor ?? snackBarTheme.disabledActionTextColor;

            return(new FlatButton(
                       onPressed: _haveTriggeredAction ? (VoidCallback)null : _handlePressed,
                       child: new Text(widget.label),
                       textColor: textColor,
                       disabledTextColor: disabledTextColor
                       ));
        }
예제 #2
0
        public override Widget build(BuildContext context)
        {
            MediaQueryData mediaQueryData = MediaQuery.of(context);

            D.assert(widget.animation != null);
            ThemeData         theme         = Theme.of(context);
            ColorScheme       colorScheme   = theme.colorScheme;
            SnackBarThemeData snackBarTheme = theme.snackBarTheme;
            bool isThemeDark = theme.brightness == Brightness.dark;

            Brightness brightness           = isThemeDark ? Brightness.light : Brightness.dark;
            Color      themeBackgroundColor = isThemeDark
                ? colorScheme.onSurface
                : Color.alphaBlend(colorScheme.onSurface.withOpacity(0.80f), colorScheme.surface);
            ThemeData inverseTheme = new ThemeData(
                brightness: brightness,
                backgroundColor: themeBackgroundColor,
                colorScheme: new ColorScheme(
                    primary: colorScheme.onPrimary,
                    primaryVariant: colorScheme.onPrimary,
                    secondary: isThemeDark ? colorScheme.primaryVariant : colorScheme.secondary,
                    secondaryVariant: colorScheme.onSecondary,
                    surface: colorScheme.onSurface,
                    background: themeBackgroundColor,
                    error: colorScheme.onError,
                    onPrimary: colorScheme.primary,
                    onSecondary: colorScheme.secondary,
                    onSurface: colorScheme.surface,
                    onBackground: colorScheme.background,
                    onError: colorScheme.error,
                    brightness: brightness
                    ),
                snackBarTheme: snackBarTheme
                );

            TextStyle        contentTextStyle   = snackBarTheme.contentTextStyle ?? inverseTheme.textTheme.subtitle1;
            SnackBarBehavior snackBarBehavior   = widget.behavior ?? snackBarTheme.behavior ?? SnackBarBehavior.fix;
            bool             isFloatingSnackBar = snackBarBehavior == SnackBarBehavior.floating;
            float            snackBarPadding    = isFloatingSnackBar ? 16.0f : 24.0f;

            CurvedAnimation heightAnimation =
                new CurvedAnimation(parent: widget.animation, curve: SnackBarUtils._snackBarHeightCurve);
            CurvedAnimation fadeInAnimation =
                new CurvedAnimation(parent: widget.animation, curve: SnackBarUtils._snackBarFadeInCurve);
            CurvedAnimation fadeOutAnimation = new CurvedAnimation(
                parent: widget.animation,
                curve: SnackBarUtils._snackBarFadeOutCurve,
                reverseCurve: new Threshold(0.0f)
                );

            var childrenList = new List <Widget>()
            {
                new SizedBox(width: snackBarPadding),
                new Expanded(
                    child: new Container(
                        padding: EdgeInsets.symmetric(vertical: SnackBarUtils._singleLineVerticalPadding),
                        child: new DefaultTextStyle(
                            style: contentTextStyle,
                            child: widget.content
                            )
                        )
                    )
            };

            if (widget.action != null)
            {
                childrenList.Add(new ButtonTheme(
                                     textTheme: ButtonTextTheme.accent,
                                     minWidth: 64.0f,
                                     padding: EdgeInsets.symmetric(horizontal: snackBarPadding),
                                     child: widget.action
                                     ));
            }
            else
            {
                childrenList.Add(new SizedBox(width: snackBarPadding));
            }

            Widget snackBar = new SafeArea(
                top: false,
                bottom: !isFloatingSnackBar,
                child: new Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: childrenList
                    )
                );

            float elevation       = widget.elevation ?? snackBarTheme.elevation ?? 6.0f;
            Color backgroundColor =
                widget.backgroundColor ?? snackBarTheme.backgroundColor ?? inverseTheme.backgroundColor;
            ShapeBorder shape = widget.shape
                                ?? snackBarTheme.shape
                                ?? (isFloatingSnackBar
                                    ? new RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0f))
                                    : null);

            snackBar = new Material(
                shape: shape,
                elevation: elevation,
                color: backgroundColor,
                child: new Theme(
                    data: inverseTheme,
                    child: mediaQueryData.accessibleNavigation
                        ? snackBar
                        : new FadeTransition(
                        opacity: fadeOutAnimation,
                        child: snackBar
                        )
                    )
                );

            if (isFloatingSnackBar)
            {
                snackBar = new Padding(
                    padding: EdgeInsets.fromLTRB(15.0f, 5.0f, 15.0f, 10.0f),
                    child: snackBar
                    );
            }

            snackBar = new Dismissible(
                key: Key.key("dismissible"),
                direction: DismissDirection.down,
                resizeDuration: null,
                onDismissed: (DismissDirection? direction) => {
                Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
            },
                child: snackBar
                );

            Widget snackBarTransition = null;

            if (mediaQueryData.accessibleNavigation)
            {
                snackBarTransition = snackBar;
            }
            else if (isFloatingSnackBar)
            {
                snackBarTransition = new FadeTransition(
                    opacity: fadeInAnimation,
                    child: snackBar
                    );
            }
            else
            {
                snackBarTransition = new AnimatedBuilder(
                    animation: heightAnimation,
                    builder: (BuildContext subContext, Widget subChild) => {
                    return(new Align(
                               alignment: AlignmentDirectional.topStart,
                               heightFactor: heightAnimation.value,
                               child: subChild
                               ));
                },
                    child: snackBar
                    );
            }

            return(new ClipRect(child: snackBarTransition));
        }