Exemple #1
0
        public override Widget build(BuildContext context)
        {
            MediaQueryData        mediaQuery    = MediaQuery.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            return(new GestureDetector(
                       onTap: () => Navigator.pop(context),
                       child: new AnimatedBuilder(
                           animation: this.widget.route.animation,
                           builder: (BuildContext _context, Widget child) => {
                float animationValue =
                    mediaQuery.accessibleNavigation ? 1.0f : this.widget.route.animation.value;
                return new ClipRect(
                    child: new CustomSingleChildLayout(
                        layoutDelegate: new _ModalBottomSheetLayout(animationValue),
                        child: new BottomSheet(
                            animationController: this.widget.route._animationController,
                            onClosing: () => Navigator.pop(_context),
                            builder: this.widget.route.builder
                            )
                        )
                    );
            }
                           )
                       ));
        }
Exemple #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));
        }
Exemple #3
0
        public override Widget buildToolbar(
            BuildContext context,
            Rect globalEditableRegion,
            float textLineHeight,
            Offset position,
            List <TextSelectionPoint> endpoints,
            TextSelectionDelegate _delegate
            )
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            MediaQueryData mediaQuery = MediaQuery.of(context);

            float toolbarHeightNeeded = mediaQuery.padding.top
                                        + CupertinoTextSelectionUtils._kToolbarScreenPadding
                                        + CupertinoTextSelectionUtils._kToolbarHeight
                                        + CupertinoTextSelectionUtils._kToolbarContentDistance;
            float availableHeight     = globalEditableRegion.top + endpoints.first().point.dy - textLineHeight;
            bool  isArrowPointingDown = toolbarHeightNeeded <= availableHeight;

            float arrowTipX = (position.dx + globalEditableRegion.left).clamp(
                CupertinoTextSelectionUtils._kArrowScreenPadding + mediaQuery.padding.left,
                mediaQuery.size.width - mediaQuery.padding.right - CupertinoTextSelectionUtils._kArrowScreenPadding
                );
            float localBarTopY = isArrowPointingDown
                  ? endpoints.first().point.dy - textLineHeight - CupertinoTextSelectionUtils._kToolbarContentDistance - CupertinoTextSelectionUtils._kToolbarHeight
                  : endpoints.last().point.dy + CupertinoTextSelectionUtils._kToolbarContentDistance;

            List <Widget> items = new List <Widget> {
            };
            Widget onePhysicalPixelVerticalDivider = new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio);
            CupertinoLocalizations localizations   = CupertinoLocalizations.of(context);
            EdgeInsets             arrowPadding    = isArrowPointingDown
                  ? EdgeInsets.only(bottom: CupertinoTextSelectionUtils._kToolbarArrowSize.height)
                  : EdgeInsets.only(top: CupertinoTextSelectionUtils._kToolbarArrowSize.height);

            void addToolbarButtonIfNeeded(
                string text,
                Predicate predicate,
                OnPressed onPressed)
            {
                if (!predicate(_delegate))
                {
                    return;
                }

                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(new CupertinoButton(
                              child: new Text(text, style: CupertinoTextSelectionUtils._kToolbarButtonFontStyle),
                              color: CupertinoTextSelectionUtils._kToolbarBackgroundColor,
                              minSize: CupertinoTextSelectionUtils._kToolbarHeight,
                              padding: CupertinoTextSelectionUtils._kToolbarButtonPadding.add(arrowPadding),
                              borderRadius: null,
                              pressedOpacity: 0.7f,
                              onPressed: () => onPressed(_delegate)
                              ));
            }

            addToolbarButtonIfNeeded(localizations.cutButtonLabel, canCut, handleCut);
            addToolbarButtonIfNeeded(localizations.copyButtonLabel, canCopy, handleCopy);
            addToolbarButtonIfNeeded(localizations.pasteButtonLabel, canPaste, handlePaste);
            addToolbarButtonIfNeeded(localizations.selectAllButtonLabel, canSelectAll, handleSelectAll);
            return(new CupertinoTextSelectionToolbar(
                       barTopY: localBarTopY + globalEditableRegion.top,
                       arrowTipX: arrowTipX,
                       isArrowPointingDown: isArrowPointingDown,
                       child: items.isEmpty() ? null : new DecoratedBox(
                           decoration: new BoxDecoration(color: CupertinoTextSelectionUtils._kToolbarDividerColor),
                           child: new Row(mainAxisSize: MainAxisSize.min, children: items)
                           )
                       ));
        }
Exemple #4
0
        public override Widget build(BuildContext context)
        {
            MediaQueryData mediaQueryData = MediaQuery.of(context);

            D.assert(this.animation != null);

            ThemeData theme     = Theme.of(context);
            ThemeData darkTheme = new ThemeData(
                brightness: Brightness.dark,
                accentColor: theme.accentColor,
                accentColorBrightness: theme.accentColorBrightness
                );

            List <Widget> children = new List <Widget> {
                new SizedBox(width: SnackBarUtils._kSnackBarPadding),
                new Expanded(
                    child: new Container(
                        padding: EdgeInsets.symmetric(vertical: SnackBarUtils._kSingleLineVerticalPadding),
                        child: new DefaultTextStyle(
                            style: darkTheme.textTheme.subhead,
                            child: this.content)
                        )
                    )
            };

            if (this.action != null)
            {
                children.Add(ButtonTheme.bar(
                                 padding: EdgeInsets.symmetric(horizontal: SnackBarUtils._kSnackBarPadding),
                                 textTheme: ButtonTextTheme.accent,
                                 child: this.action
                                 ));
            }
            else
            {
                children.Add(new SizedBox(width: SnackBarUtils._kSnackBarPadding));
            }

            CurvedAnimation heightAnimation =
                new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarHeightCurve);
            CurvedAnimation fadeAnimation = new CurvedAnimation(parent: this.animation,
                                                                curve: SnackBarUtils._snackBarFadeCurve, reverseCurve: new Threshold(0.0f));
            Widget snackbar = new SafeArea(
                top: false,
                child: new Row(
                    children: children,
                    crossAxisAlignment: CrossAxisAlignment.center
                    )
                );

            snackbar = new Dismissible(
                key: Key.key("dismissible"),
                direction: DismissDirection.down,
                resizeDuration: null,
                onDismissed: (DismissDirection? direction) => {
                Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
            },
                child: new Material(
                    elevation: 6.0f,
                    color: this.backgroundColor ?? SnackBarUtils._kSnackBackground,
                    child: new Theme(
                        data: darkTheme,
                        child: mediaQueryData.accessibleNavigation
                            ? snackbar
                            : new FadeTransition(
                            opacity: fadeAnimation,
                            child: snackbar
                            )
                        )
                    )
                );

            return(new ClipRect(
                       child: mediaQueryData.accessibleNavigation
                    ? snackbar
                    : new AnimatedBuilder(
                           animation: heightAnimation,
                           builder: (BuildContext subContext, Widget child) => {
                return new Align(
                    alignment: Alignment.topLeft,
                    heightFactor: heightAnimation.value,
                    child: child
                    );
            },
                           child: snackbar
                           )
                       ));
        }
Exemple #5
0
        public override Widget build(BuildContext context)
        {
            List <Widget> stacked = new List <Widget> {
            };

            MediaQueryData existingMediaQuery = MediaQuery.of(context);
            MediaQueryData newMediaQuery      = MediaQuery.of(context);

            Widget content = new _TabSwitchingView(
                currentTabIndex: _controller.index,
                tabNumber: widget.tabBar.items.Count,
                tabBuilder: widget.tabBuilder
                );
            EdgeInsets contentPadding = EdgeInsets.zero;

            if (widget.resizeToAvoidBottomInset)
            {
                newMediaQuery  = newMediaQuery.removeViewInsets(removeBottom: true);
                contentPadding = EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom);
            }

            if (widget.tabBar != null &&
                (!widget.resizeToAvoidBottomInset ||
                 widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom))
            {
                float bottomPadding = widget.tabBar.preferredSize.height + existingMediaQuery.padding.bottom;

                if (widget.tabBar.opaque(context))
                {
                    contentPadding = EdgeInsets.only(bottom: bottomPadding);
                    newMediaQuery  = newMediaQuery.removePadding(removeBottom: true);
                }
                else
                {
                    newMediaQuery = newMediaQuery.copyWith(
                        padding: newMediaQuery.padding.copyWith(
                            bottom: bottomPadding
                            )
                        );
                }
            }

            content = new MediaQuery(
                data: newMediaQuery,
                child: new Padding(
                    padding: contentPadding,
                    child: content
                    )
                );
            stacked.Add(content);
            stacked.Add(
                new MediaQuery(
                    data: existingMediaQuery.copyWith(textScaleFactor: 1),
                    child: new Align(
                        alignment: Alignment.bottomCenter,
                        child: widget.tabBar.copyWith(
                            currentIndex: _controller.index,
                            onTap: (int newIndex) => {
                _controller.index = newIndex;
                if (widget.tabBar.onTap != null)
                {
                    widget.tabBar.onTap(newIndex);
                }
            }
                            )
                        )
                    )
                );

            return(new DecoratedBox(
                       decoration: new BoxDecoration(
                           color: CupertinoDynamicColor.resolve(widget.backgroundColor, context)
                           ?? CupertinoTheme.of(context).scaffoldBackgroundColor
                           ),
                       child: new Stack(
                           children: stacked
                           )
                       ));
        }
Exemple #6
0
        public override Widget build(BuildContext context)
        {
            Widget paddedContent = widget.child;

            MediaQueryData existingMediaQuery = MediaQuery.of(context);

            if (widget.navigationBar != null)
            {
                float topPadding = widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top;

                float bottomPadding = widget.resizeToAvoidBottomInset
                    ? existingMediaQuery.viewInsets.bottom
                    : 0.0f;

                EdgeInsets newViewInsets = widget.resizeToAvoidBottomInset
                    ? existingMediaQuery.viewInsets.copyWith(bottom: 0.0f)
                    : existingMediaQuery.viewInsets;

                bool fullObstruction = widget.navigationBar.shouldFullyObstruct(context);

                if (fullObstruction == true)
                {
                    paddedContent = new MediaQuery(
                        data: existingMediaQuery
                        .removePadding(removeTop: true)
                        .copyWith(
                            viewInsets: newViewInsets
                            ),
                        child: new Padding(
                            padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding),
                            child: paddedContent
                            )
                        );
                }
                else
                {
                    paddedContent = new MediaQuery(
                        data: existingMediaQuery.copyWith(
                            padding: existingMediaQuery.padding.copyWith(
                                top: topPadding
                                ),
                            viewInsets: newViewInsets
                            ),
                        child: new Padding(
                            padding: EdgeInsets.only(bottom: bottomPadding),
                            child: paddedContent
                            )
                        );
                }
            }
            else
            {
                float bottomPadding = widget.resizeToAvoidBottomInset
                    ? existingMediaQuery.viewInsets.bottom
                    : 0.0f;
                paddedContent = new Padding(
                    padding: EdgeInsets.only(bottom: bottomPadding),
                    child: paddedContent
                    );
            }
            List <Widget> childrenWigets = new List <Widget>();

            childrenWigets.Add(new PrimaryScrollController(
                                   controller: _primaryScrollController,
                                   child: paddedContent
                                   ));
            if (widget.navigationBar != null)
            {
                childrenWigets.Add(new Positioned(
                                       top: 0.0f,
                                       left: 0.0f,
                                       right: 0.0f,
                                       child: new MediaQuery(
                                           data: existingMediaQuery.copyWith(textScaleFactor: 1),
                                           child: widget.navigationBar
                                           )
                                       ));
            }
            childrenWigets.Add(new Positioned(
                                   top: 0.0f,
                                   left: 0.0f,
                                   right: 0.0f,
                                   height: existingMediaQuery.padding.top,
                                   child: new GestureDetector(
                                       onTap: _handleStatusBarTap
                                       )

                                   ));

            return(new DecoratedBox(
                       decoration: new BoxDecoration(
                           color: CupertinoDynamicColor.resolve(widget.backgroundColor, context)
                           ?? CupertinoTheme.of(context).scaffoldBackgroundColor
                           ),
                       child: new Stack(
                           children: childrenWigets)));
        }