是否可以在Flutter Web中创建指向同一页面中各个部分的链接? [英] Is it possible to create links to sections in the same page in flutter web?

查看:106
本文介绍了是否可以在Flutter Web中创建指向同一页面中各个部分的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Flutter Web创建网站,但无法导航至同一页面中的部分.这是我要使用颤振要实现的示例.

I want to create a website using flutter web but I'm unable to navigate to sections in the same page. Here's an example of what I want to achieve using flutter.

P.S.导航器无法正常工作:

P.S. Navigator is not working:

推荐答案

我使用 PageView

class MyHomePage extends StatelessWidget {

  var list = ["Home","Services", "Work", "About"];
  var colors = [Colors.orange, Colors.blue, Colors.red, Colors.green];

  PageController controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  width: 50,
                  height: 50,
                  margin: EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.circular(10)
                  ),
                ),
                Spacer(),
                Row(
                  children: List.generate(3, (index){
                    return GestureDetector(
                      onTap: (){
                        _scrollToIndex(index);
                      },
                      child: Container(
                        margin: EdgeInsets.all(8),
                        child: Text(
                          list[index+1]
                        ),
                      ),
                    );
                  }),
                )
              ],
            ),
            Expanded(
              child : PageView(
                scrollDirection: Axis.vertical,
                pageSnapping: false,
                controller: controller,
                children: List.generate(list.length, (index){
                  return Container(
                    width: MediaQuery.of(context).size.width,
                    height: double.maxFinite,
                    color: colors[index],
                    child: Center(
                      child: Text(
                          list[index],
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 50
                          ),
                      ),
                    ),
                  );
                })
              ),
            ),
          ],
        )
      ),
    );
  }

  void _scrollToIndex(int index) {
    controller.animateToPage(index + 1, duration: Duration(seconds: 2), curve: Curves.fastLinearToSlowEaseIn);
  }
}

输出:

这篇关于是否可以在Flutter Web中创建指向同一页面中各个部分的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆