简体   繁体   English

如何在 Flutter 中向 Cupertino Segmented Control 添加网格

[英]How to add a grid to Cupertino Segmented Control in Flutter

I was referring to this link on Git Hub and I'm trying to add a grid to the segment.我指的是 Git Hub 上的这个链接,我正在尝试向该段添加网格。

My objective is to add images in a grid view to a segment in Cupertino Segmented Control我的目标是将网格视图中的图像添加到 Cupertino Segmented Control 中的段

return Scaffold(
        appBar: CupertinoNavigationBar(
          middle: Text("awrdfsfsdfs"),
          automaticallyImplyLeading: true,
          transitionBetweenRoutes: true,
          previousPageTitle: AppLocalizations.of(context).tr('alerts.back'),
        ), 
  body: Column(
  crossAxisAlignment: CrossAxisAlignment.stretch,
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Expanded(
      child: ListView(
        shrinkWrap: true,
        scrollDirection: Axis.vertical,
        padding: EdgeInsets.only(top: 20),
        children: <Widget>[
          CupertinoSegmentedControl(
            children: {
              0: Text(AppLocalizations.of(context).tr('titles.secImg')),
              1: Text(AppLocalizations.of(context).tr('titles.secQuest')),
            },
            groupValue: _selectedIndexValue,
            onValueChanged: (value) {
              setState(() => _selectedIndexValue = value);
            },
          ),

          _selectedIndexValue == 0 ? IosFirstPage() : IosSecondPage()
        ],
      ),
    )
  ],
),
);
 }
}

class IosFirstPage extends StatelessWidget {
  const IosFirstPage({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    var imgList = [ ];
    return Flex(
    direction: Axis.vertical,
  children: <Widget>[
    Container(
      padding: EdgeInsets.only(top: 10,left: 10),
      child: Row(
        children: <Widget>[
          Text(AppLocalizations.of(context).tr('titles.selectSecImg'),style: textTheme.subtitle,textAlign: TextAlign.left,textScaleFactor: 1.2,),

        ],
      )
    ),
    Container(
      width: MediaQuery
          .of(context)
          .size
          .width,
      height: MediaQuery.of(context).size.height*0.64, //adjust this resize the scroll view of the images
      margin: EdgeInsets.only(top: 10,left: 10,right: 10),
      color: Colors.white30,
      child: GridView.builder(
        itemCount: imgList.length,
        gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 5),
        itemBuilder: (BuildContext context, int index) {
          return new GestureDetector(
            child: new Card(
              elevation: 1.0,
              child: new Container(
                  alignment: Alignment.center,
                  margin: new EdgeInsets.only(
                      top: 10.0, bottom: 10.0),
                  child: new Image.asset(imgList[index], scale: 0.5,)
              ),
            ),
            onTap: () {
              print(index);
              /*showDialog(
              barrierDismissible: false,
              context: context,
              child: new CupertinoAlertDialog(
                title: new Column(
                  children: <Widget>[
                    new Text("GridView"),
                    new Icon(
                      Icons.favorite,
                      color: Colors.red,
                    ),
                  ],
                ),
                content: new Text( imgList[index]),
                actions: <Widget>[
                  new FlatButton(
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                      child: new Text("OK"))
                ],
              ));*/
            },
          );
        },
      ),
    ),

  ],

);
 }
}

class IosSecondPage extends StatelessWidget {
const IosSecondPage({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container();.
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM