0

现在我使用 SliverAppBar,如果我想将文本“Choices”(在图片中)移动到右侧,然后单击(单击文本)它会转到另一个页面。我该怎么办!!我做的那个离边界太近了,太低了,不在同一水平线上。

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

    @override
    Widget build(BuildContext context) {
         return CustomScrollView(
            slivers: [
                SliverAppBar(
                  pinned: true,
                  backgroundColor: Colors.black,
                  flexibleSpace: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                      GestureDetector(
                        child: Container(
                          alignment: Alignment.bottomRight,
                          child: Text(
                             "Choices",
                             style: TextStyle(color: Colors.white,fontSize:20)
                          ),
                        ),
                  onTap: (){
                    Route route = MaterialPageRoute(builder: (context)=>Choices());
                    Navigator.push(context, route);
                  },
                )
            ],
         );

我的应用页面

我的用户界面

4

1 回答 1

0

不使用灵活空间使用操作:

 SliverAppBar(
      pinned: true,
      backgroundColor: Colors.black,
      actions: [
        TextButton(
          onPressed: () {
            Route route = MaterialPageRoute(builder: (context) => Choices());
            Navigator.push(context, route);
          },
          child: Text(
            "Choices",
            style: TextStyle(color: Colors.white, fontSize: 20),
          ),
        )
      ],
     [...]
    )

如果右侧需要更多空间,请使用 Padding 包裹 textButton :

SliverAppBar(
      pinned: true,
      backgroundColor: Colors.black,
      actions: [
        Padding(
          padding: EdgeInsets.only(right: 10),
          child: TextButton(
            onPressed: () {
              Route route = MaterialPageRoute(builder: (context) => Choices());
              Navigator.push(context, route);
            },
            child: Text(
              "Choices",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          ),
        )
      ],
      [...]
    )
于 2021-07-19T16:11:04.803 回答