listView项目滑动右打开新屏幕

发布于 2025-02-03 05:57:51 字数 3138 浏览 4 评论 0原文

如何通过在listView项目的右侧打开新屏幕,类似于snapchat app。这是我想实现的视频链接。 link

我试图使用ListView Slidable检查,但是没有选择到新屏幕上的选项。 以下是两个屏幕的示例飞镖代码。通过刷listView项目,我想打开testpage.dart屏幕。如何在颤抖中实现这一目标?

firstpage.dart

ListView.builder(
          itemCount: 10,
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          itemBuilder: (BuildContext context, int index) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  Row(
                    children: [
                      ClipOval(
                        child: Image.network(
                          'https://googleflutter.com/sample_image.jpg',
                          width: 50,
                          height: 50,
                          fit: BoxFit.cover,
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(
                            right: 10.0),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment:
                              MainAxisAlignment
                                  .spaceBetween,
                              children: [
                                Text(
                                  'Person 1',
                                  style: TextStyle(
                                    color: Colors.red
                                  ),
                                ),
                                const FittedBox(
                                  fit: BoxFit.fitWidth,
                                  child: Text(
                                    'last seen at 8:22 PM'
                                )
                              ],
                            ),
                            Padding(
                              padding: const EdgeInsets.only(
                                  top: 5.0),
                              child: SizedBox(
                                width: MediaQuery.of(context)
                                    .size
                                    .width *
                                    0.50,
                                child:Text('test'),
                              ),
                            )
                          ],
                        ),
                      ),],),],),);}),

testpage.dart

    class TestPage extends StatefulWidget {
  const TestPage({Key? key}) : super(key: key);

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.redAccent,
      body: Container(),
    );
  }
}

How to open new screen by swiping to the right of listview item similar to as snapchat app. This is the video link that i want to achieve this.
link

I tried to check with listview slidable but there is no option for navigating to new screen.
Below is the sample dart code of two screens. By swiping right of listview item i want to open TestPage.dart screen. How to achieve this in Flutter?

FirstPage.dart

ListView.builder(
          itemCount: 10,
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
          itemBuilder: (BuildContext context, int index) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                children: [
                  Row(
                    children: [
                      ClipOval(
                        child: Image.network(
                          'https://googleflutter.com/sample_image.jpg',
                          width: 50,
                          height: 50,
                          fit: BoxFit.cover,
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(
                            right: 10.0),
                        child: Column(
                          children: [
                            Row(
                              mainAxisAlignment:
                              MainAxisAlignment
                                  .spaceBetween,
                              children: [
                                Text(
                                  'Person 1',
                                  style: TextStyle(
                                    color: Colors.red
                                  ),
                                ),
                                const FittedBox(
                                  fit: BoxFit.fitWidth,
                                  child: Text(
                                    'last seen at 8:22 PM'
                                )
                              ],
                            ),
                            Padding(
                              padding: const EdgeInsets.only(
                                  top: 5.0),
                              child: SizedBox(
                                width: MediaQuery.of(context)
                                    .size
                                    .width *
                                    0.50,
                                child:Text('test'),
                              ),
                            )
                          ],
                        ),
                      ),],),],),);}),

TestPage.dart

    class TestPage extends StatefulWidget {
  const TestPage({Key? key}) : super(key: key);

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.redAccent,
      body: Container(),
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走干脆点 2025-02-10 05:57:51

您可以通过这样使用可忽视的小部件来做到这一点:

ListView.builder(itemBuilder: ((context, index) => Dismissible(
  key: UniqueKey(),
  child: ListTile(),
  direction: DismissDirection.startToEnd,
  onDismissed: (DismissDirection dismissDirection){
    Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: DetailScreen()));
  },

)
)
);

You can do it by using Dismissible widget like this:

ListView.builder(itemBuilder: ((context, index) => Dismissible(
  key: UniqueKey(),
  child: ListTile(),
  direction: DismissDirection.startToEnd,
  onDismissed: (DismissDirection dismissDirection){
    Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: DetailScreen()));
  },

)
)
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文