我如何在flutter listView中仅制作一个可滑动的幻灯片?

发布于 2025-02-03 12:51:46 字数 4764 浏览 4 评论 0原文

import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

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

  @override
  State<MapSelectPage> createState() => _MapSelectPageState();
}

class _MapSelectPageState extends State<MapSelectPage> {
  @override
  Widget build(BuildContext context) {
    Get.put<MapSelectViewController>(MapSelectViewController());
    MapSelectViewController _controller = Get.find<MapSelectViewController>();
    return Scaffold(
      body: Obx(() {
        if (_controller.mapList.value == null) {
          return Center(
            child: TLoader.Loader(),
          );
        } else {
          return SafeArea(
            child: RefreshIndicator(
              child: ListView(
                children: [
                  _pageTitle(),
                  for (MapData data in _controller.mapList.value!) _mapButton(),
                  _createMapButton(),
                ],
              ),
              onRefresh: () async {
                _controller.getMapList();
              },
            ),
          );
        }
      }),
    );
  }
}

// 페이지 타이틀
Widget _pageTitle() {
  return Column(
    children: [
      Text(
        "지도를 선택하세요!",
        style: TText.style.displaySmall,
      )
    ],
  );
}

// 지도 생성버튼
Widget _createMapButton() {
  return Container(
    padding: const EdgeInsets.all(10),
    child: InkWell(
      onTap: () => Get.to(const MapCreatePage()),
      child: TCard(
          child: Column(
        children: [
          const SizedBox(
            height: 200,
            child: RiveAnimation.asset(
              "images/ani/new_book.riv",
            ),
          ),
          const SizedBox(height: 10),
          Text("새로운 지도를 생성하세요!!", style: TText.style.titleLarge),
        ],
      )),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(10),
      child: TCard(
        child: Container(
          width: double.infinity,
          child: Slidable(
            endActionPane: ActionPane(
              motion: const ScrollMotion(),
              children: [
                SlidableAction(
                  icon: Icons.ac_unit,
                  label: "test",
                  onPressed: (context) {
                    print("112312");
                  },
                )
              ],
            ),
            child: Container(
              width: double.infinity,
              child: InkWell(
                onTap: () {
                  Slidable.of(context)!.close();
                },
                child: Container(
                  padding: const EdgeInsets.all(10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "data",
                        style: TText.style.titleLarge,
                      ),
                      const SizedBox(height: 10),
                      Text(
                        "data",
                        style: TText.style.titleSmall,
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

以上是使用我的可滑动的代码, 我有一个可滑动的墨水窗口小部件,当我单击它时,滑块应该关闭,但它不会关闭,

═══════= Exception caught by gesture =====
Null check operator used on a null value
═══════= ===============

返回此错误 }

当我滑入ListView Slidable并单击Inkwell时,SLID应该关闭,但是它不会关闭错误,我该如何关闭幻灯片?

slidable.of(context)!。close();

单击时,它变为null。

slidable.of(上下文)?close();

我们不仅不能一直这样做,而且这将发生。

tcard自定义小部件是

import 'package:flutter/material.dart';

class TCard extends StatelessWidget {
  const TCard({
    Key? key,
    required this.child,
    this.padding = 5,
    this.onTap,
  }) : super(key: key);

  final Widget child;
  final Function()? onTap;
  final double padding;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Ink(
        padding: EdgeInsets.all(padding),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          color: Colors.white,
          boxShadow: const [
            BoxShadow(
              color: Colors.grey,
              offset: Offset(1, 2),
              blurRadius: 2,
              spreadRadius: 2,
            ),
          ],
        ),
        child: child,
      ),
    );
  }
}
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

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

  @override
  State<MapSelectPage> createState() => _MapSelectPageState();
}

class _MapSelectPageState extends State<MapSelectPage> {
  @override
  Widget build(BuildContext context) {
    Get.put<MapSelectViewController>(MapSelectViewController());
    MapSelectViewController _controller = Get.find<MapSelectViewController>();
    return Scaffold(
      body: Obx(() {
        if (_controller.mapList.value == null) {
          return Center(
            child: TLoader.Loader(),
          );
        } else {
          return SafeArea(
            child: RefreshIndicator(
              child: ListView(
                children: [
                  _pageTitle(),
                  for (MapData data in _controller.mapList.value!) _mapButton(),
                  _createMapButton(),
                ],
              ),
              onRefresh: () async {
                _controller.getMapList();
              },
            ),
          );
        }
      }),
    );
  }
}

// 페이지 타이틀
Widget _pageTitle() {
  return Column(
    children: [
      Text(
        "지도를 선택하세요!",
        style: TText.style.displaySmall,
      )
    ],
  );
}

// 지도 생성버튼
Widget _createMapButton() {
  return Container(
    padding: const EdgeInsets.all(10),
    child: InkWell(
      onTap: () => Get.to(const MapCreatePage()),
      child: TCard(
          child: Column(
        children: [
          const SizedBox(
            height: 200,
            child: RiveAnimation.asset(
              "images/ani/new_book.riv",
            ),
          ),
          const SizedBox(height: 10),
          Text("새로운 지도를 생성하세요!!", style: TText.style.titleLarge),
        ],
      )),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.all(10),
      child: TCard(
        child: Container(
          width: double.infinity,
          child: Slidable(
            endActionPane: ActionPane(
              motion: const ScrollMotion(),
              children: [
                SlidableAction(
                  icon: Icons.ac_unit,
                  label: "test",
                  onPressed: (context) {
                    print("112312");
                  },
                )
              ],
            ),
            child: Container(
              width: double.infinity,
              child: InkWell(
                onTap: () {
                  Slidable.of(context)!.close();
                },
                child: Container(
                  padding: const EdgeInsets.all(10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "data",
                        style: TText.style.titleLarge,
                      ),
                      const SizedBox(height: 10),
                      Text(
                        "data",
                        style: TText.style.titleSmall,
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

Above is the code using my slideable,
I have an inkwell widget inside a slidable, and when I click on it, that slid should close, but it doesn't close,

═══════= Exception caught by gesture =====
Null check operator used on a null value
═══════= ===============

returns this error
}

When I slide in listview slidable and click inkwell, the slid should close, but it doesn't close with an error, how can I close the slide?

Slidable.of(context)!.close();

When clicked, it becomes null.

Slidable.of(context)?.close();

Not only couldn't we do it all the way, but this was about to happen.

tcard custom widget is

import 'package:flutter/material.dart';

class TCard extends StatelessWidget {
  const TCard({
    Key? key,
    required this.child,
    this.padding = 5,
    this.onTap,
  }) : super(key: key);

  final Widget child;
  final Function()? onTap;
  final double padding;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Ink(
        padding: EdgeInsets.all(padding),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5),
          color: Colors.white,
          boxShadow: const [
            BoxShadow(
              color: Colors.grey,
              offset: Offset(1, 2),
              blurRadius: 2,
              spreadRadius: 2,
            ),
          ],
        ),
        child: child,
      ),
    );
  }
}

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

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

发布评论

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

评论(1

好菇凉咱不稀罕他 2025-02-10 12:51:46

至于错误,您可以在使用NULL之前检查NULL。

或只是替换

 Slidable.of(context)!.close();

 Slidable.of(context)?.close();

As for the error, You can check null before using it.

Or just replace

 Slidable.of(context)!.close();

with

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