简体   繁体   English

如何实现List的gridview水平滚动(轮播)<widget> function 在 flutter 中?</widget>

[英]how to achieve gridview horizontally scrolling (carousell) for List<Widget> function in flutter?

I have a list of menu and it's overpopulate inside one page because the list of menu is more than expected, I want to change this listview into gridview with horizontally scrolling or carousell swipe, so other menu (card) will be shown when I swipe it to left, previously I use List<Widget> function and ListView() to create a list of card.我有一个菜单列表,它在一页内填充过多,因为菜单列表超出预期,我想通过水平滚动或轮播滑动将此列表视图更改为 gridview,因此当我滑动它时将显示其他菜单(卡片)在左侧,我之前使用List<Widget> functionListView()创建卡片列表。 I want three stack of horizontal card and when I swipe it to the left, it will showing other three stack horizontal card, just like this:我想要三叠横牌,当我向左滑动时,它会显示其他三叠横牌,就像这样:

在此处输入图像描述

this is my previous code:这是我以前的代码:

      Padding(
        padding: const EdgeInsetsDirectional.all(Dimensions.paddingSizeDefault),
        child: Obx(() => ListView(
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              addSemanticIndexes: false,
              children: buildMainMenu(),
            )));

buildMainMenu() is the name of List<Widget> function buildMainMenu()List<Widget> function

To create a swipeable stack widget use flutter_card_swiper package ( https://pub.dev/packages/flutter_card_swiper ).要创建可滑动的堆栈小部件,请使用flutter_card_swiper package ( https://pub.dev/packages/flutter_card_swiper )。

There are plenty of swipeable packages: -有很多可滑动的包裹:-

https://pub.dev/packages?q=swipe+card https://pub.dev/packages?q=swipe+card

Sample Code: -示例代码:-

class Example extends StatelessWidget {
  List<Container> cards = [
    Container(
      alignment: Alignment.center,
      child: const Text('1'),
      color: Colors.blue,
    ),
    2nd Widget,
    3nd Widget,
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Flexible(
        child: CardSwiper(
          cards: cards,
        ),
      ),
    );
  }
} 

Complete Code: -完整代码:-

import 'package:flutter/material.dart';
import 'package:appinio_swiper/appinio_swiper.dart';
import 'package:flutter/cupertino.dart';

void main() => runApp(const Example());

class Example extends StatefulWidget {
  const Example({super.key});

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  List<Container> cards = [
    Container(
      alignment: Alignment.center,
      color: CupertinoColors.activeBlue,
      child: const Text('1'),
    ),
    Container(
      alignment: Alignment.center,
      color: CupertinoColors.activeGreen,
      child: const Text('2'),
    ),
    Container(
      alignment: Alignment.center,
      color: CupertinoColors.activeOrange,
      child: const Text('3'),
    ),
    Container(
      alignment: Alignment.center,
      color: CupertinoColors.systemPink,
      child: const Text('4'),
    )
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: CupertinoPageScaffold(
          child: Center(
            child: SizedBox(
              height: 500,
              width: 400,
              child: AppinioSwiper(
                allowUnswipe: false,
                maxAngle: 2,
                direction: AppinioSwiperDirection.left,
                cards: cards,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Output: - Output:-

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

相关问题 "Flutter:如何禁用 GridView 小部件的滚动,但为整个页面启用滚动?" - Flutter: How do I disable scrolling for a GridView widget, but have scrolling enabled for the page as a whole? Android水平滚动GridView - Android Horizontally scrolling GridView 如何实现类似自定义搜寻栏的类似水平滚动小部件? - How to achieve a similar horizontal scrolling widget like a custom seekbar? 水平滚动布局列表 - Horizontally scrolling layout list 开发带有抖动的电视应用程序,如何实现滚动效果 - Develop a TV application with flutter, how to achieve scrolling effect 如何在flutter中覆盖Widget功能 - How to override Widget function in flutter 如何实现水平列表但垂直滚动的recyclerview android - How to achieve recyclerview with horizontal list but vertical scrolling android 如何在 Flutter 中将 Gridview.count() 中的最后一个小部件居中? - How to center the last widget in Gridview.count() in Flutter? 在 Flutter 中创建可水平和垂直滚动的小部件 - Creating a widget that is both horizontally and vertically scrollable in Flutter Flutter:如何在 flutter 中实现这样的径向小部件? 圆形面包屑/步骤进度指示器 - Flutter: How to achieve a Radial Widget like this in flutter? Circular breadcrumbs/ step progress indicator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM