예제 #1
0
 public _CategoryItem(
     Key key = null,
     GalleryDemoCategory category = null,
     VoidCallback onTap           = null
     ) : base(key: key)
 {
     this.category = category;
     this.onTap    = onTap;
 }
예제 #2
0
        public override Widget build(BuildContext context)
        {
            float aspectRatio = 160.0f / 180.0f;
            List <GalleryDemoCategory> categoriesList = this.categories.ToList();
            int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3;

            return(new SingleChildScrollView(
                       key: Key.key("categories"),
                       child: new LayoutBuilder(
                           builder: (BuildContext subContext, BoxConstraints constraints) =>
            {
                float columnWidth = constraints.biggest.width / columnCount;
                float rowHeight = Mathf.Min(225.0f, columnWidth * aspectRatio);
                int rowCount = (this.categories.Count() + columnCount - 1) / columnCount;

                var children = new List <Widget>();

                for (var i = 0; i < rowCount; i++)
                {
                    var rowIndex = i;
                    int columnCountForRow = rowIndex == rowCount - 1
                                ? this.categories.Count() - columnCount * Mathf.Max(0, rowCount - 1)
                                : columnCount;

                    var subChildren = new List <Widget>();

                    for (var j = 0; j < columnCountForRow; j++)
                    {
                        var columnIndex = j;
                        int index = rowIndex * columnCount + columnIndex;
                        GalleryDemoCategory category = categoriesList[index];

                        subChildren.Add(new SizedBox(width: columnWidth,
                                                     height: rowHeight,
                                                     child: new _CategoryItem(
                                                         category: category,
                                                         onTap: () => { this.onCategoryTap(category); }
                                                         )
                                                     ));
                    }

                    children.Add(new Row(
                                     children: subChildren
                                     ));
                }

                return new RepaintBoundary(
                    child: new Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: children
                        )
                    );
            })));
        }
예제 #3
0
        public bool Equals(GalleryDemoCategory other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            return(icon.Equals(other.icon) && name == other.name);
        }
예제 #4
0
        public override Widget build(BuildContext context)
        {
            float aspectRatio = 160.0f / 180.0f;
            List <GalleryDemoCategory> categoriesList = this.categories.ToList();
            int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3;

            return(new SingleChildScrollView(
                       key: new PageStorageKey <string>("categories"),
                       child: new LayoutBuilder(
                           builder: (_, constraints) => {
                float columnWidth = constraints.biggest.width / columnCount;
                float rowHeight = Mathf.Min(225.0f, columnWidth * aspectRatio);
                int rowCount = (categoriesList.Count + columnCount - 1) / columnCount;

                return new RepaintBoundary(
                    child: new Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: Enumerable.Range(0, rowCount).Select(rowIndex => {
                    int columnCountForRow = rowIndex == rowCount - 1
                                        ? categoriesList.Count - columnCount * Mathf.Max(0, rowCount - 1)
                                        : columnCount;

                    return (Widget) new Row(
                        children: Enumerable.Range(0, columnCountForRow).Select(columnIndex => {
                        int index = rowIndex * columnCount + columnIndex;
                        GalleryDemoCategory category = categoriesList[index];

                        return (Widget) new SizedBox(
                            width: columnWidth,
                            height: rowHeight,
                            child: new _CategoryItem(
                                category: category,
                                onTap: () => { this.onCategoryTap(category); }
                                )
                            );
                    }).ToList()
                        );
                }).ToList()
                        )
                    );
            }
                           )
                       ));
        }
예제 #5
0
 public GalleryDemo(
     string title    = null,
     IconData icon   = null,
     string subtitle = null,
     GalleryDemoCategory category = null,
     string routeName             = null,
     string documentationUrl      = null,
     WidgetBuilder buildRoute     = null
     )
 {
     D.assert(title != null);
     D.assert(icon != null);
     D.assert(category != null);
     D.assert(routeName != null);
     D.assert(buildRoute != null);
     this.title            = title;
     this.icon             = icon;
     this.subtitle         = subtitle;
     this.category         = category;
     this.routeName        = routeName;
     this.documentationUrl = documentationUrl;
     this.buildRoute       = buildRoute;
 }
예제 #6
0
        public override Widget build(BuildContext context)
        {
            ThemeData      theme      = Theme.of(context);
            bool           isDark     = theme.brightness == Brightness.dark;
            MediaQueryData media      = MediaQuery.of(context);
            bool           centerHome = media.orientation == Orientation.portrait && media.size.height < 800.0;

            Curve switchOutCurve = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);
            Curve switchInCurve  = new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn);

            Widget home = new Scaffold(
                key: this._scaffoldKey,
                backgroundColor: isDark ? HomeUtils._kUIWidgetsBlue : theme.primaryColor,
                body: new SafeArea(
                    bottom: false,
                    child: new WillPopScope(
                        onWillPop: () => {
                if (this._category != null)
                {
                    this.setState(() => this._category = null);
                    return(Promise <bool> .Resolved(false));
                }

                return(Promise <bool> .Resolved(true));
            },
                        child: new Backdrop(
                            backTitle: new Text("Options"),
                            backLayer: this.widget.optionsPage,
                            frontAction: new AnimatedSwitcher(
                                duration: HomeUtils._kFrontLayerSwitchDuration,
                                switchOutCurve: switchOutCurve,
                                switchInCurve: switchInCurve,
                                child: this._category == null
                                    ? (Widget) new _UIWidgetsLogo(isDark: this.widget.options?.theme == GalleryTheme.kDarkGalleryTheme)
                                    : new IconButton(
                                    icon: new BackButtonIcon(),
                                    tooltip: "Back",
                                    onPressed: () => this.setState(() => this._category = null)
                                    )
                                ),
                            frontTitle: new AnimatedSwitcher(
                                duration: HomeUtils._kFrontLayerSwitchDuration,
                                child: this._category == null
                                    ? new Text("UIWidgets gallery")
                                    : new Text(this._category.name)
                                ),
                            frontHeading: this.widget.testMode ? null : new Container(height: 24.0f),
                            frontLayer: new AnimatedSwitcher(
                                duration: HomeUtils._kFrontLayerSwitchDuration,
                                switchOutCurve: switchOutCurve,
                                switchInCurve: switchInCurve,
                                layoutBuilder: centerHome ? _centerHomeLayout : _topHomeLayout,
                                child: this._category != null
                                    ? (Widget) new _DemosPage(this._category)
                                    : new _CategoriesPage(
                                    categories: DemoUtils.kAllGalleryDemoCategories,
                                    onCategoryTap: (GalleryDemoCategory category) => {
                this.setState(() => this._category = category);
            }
                                    )
                                )
                            )
                        )
                    )
                );

            D.assert(() => {
                GalleryHome.showPreviewBanner = false;
                return(true);
            });

            if (GalleryHome.showPreviewBanner)
            {
                home = new Stack(
                    fit: StackFit.expand,
                    children: new List <Widget> {
                    home,
                    new FadeTransition(
                        opacity: new CurvedAnimation(parent: this._controller, curve: Curves.easeInOut),
                        child: new Banner(
                            message: "PREVIEW",
                            location: BannerLocation.topEnd
                            )
                        )
                }
                    );
            }

            home = new AnnotatedRegion <SystemUiOverlayStyle>(
                child: home,
                value: SystemUiOverlayStyle.light
                );

            return(home);
        }
예제 #7
0
 public _DemosPage(GalleryDemoCategory category)
 {
     this.category = category;
 }