0

我创建了一个带有容器框的 ListView 作为小部件。我想要一个特定的容器将 onTap 扩展到特定的屏幕高度和宽度。我需要帮助来实现这一点。我在 Adob​​eXD 上做了一个原型。

AdobeXD 原型 GIF

我是新来的颤振,任何形式的帮助表示赞赏。

4

2 回答 2

1

一个名为flutter swiper的flutter插件可能会帮助您实现您想要实现的目标。访问这个 pub dev,你可以阅读文档。输出

于 2020-10-21T11:18:11.763 回答
0

兄弟,你去吧,虽然它没有模糊背景,但我认为它会让你继续前进。

它的工作原理是这样的:

在此处输入图像描述

下面的代码你可以复制粘贴。我在代码中添加了注释以便更好地理解它。干杯:)

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeApp(),
    );
  }
}

class HomeApp extends StatefulWidget {
  @override
  _HomeAppState createState() => _HomeAppState();
}

class _HomeAppState extends State<HomeApp> {
  // Items in the list --> Custom Widgets
  List<Widget> arr = [
    ListContainerHere(),
    ListContainerHere(),
    ListContainerHere(),
    ListContainerHere(),
    ListContainerHere(),
    ListContainerHere(),
  ];

  Widget getListWidget(List<Widget> items) {
    List<Widget> list = new List<Widget>();

    for (var i = 0; i <= items.length; i++) {
      list.add(new ListContainerHere(
        index: i,
      ));
    }
    return Row(children: list);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter App :)"),
      ),
      body: Center(
        // Using a 'Row' as Horizontal ListView
        child: SingleChildScrollView(
            scrollDirection: Axis.horizontal, child: getListWidget(arr)),
      ),
    );
  }
}

// Widgets that will be rendered in the Horizontal Row
class ListContainerHere extends StatefulWidget {
  final int index;
  ListContainerHere({this.index});

  @override
  _ListContainerHereState createState() => _ListContainerHereState();
}

class _ListContainerHereState extends State<ListContainerHere> {
  // Varibale to change the height and width accordingly
  // Initally no item will be expanded
  bool isExpanded = false;
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: GestureDetector(
        onTap: () {
          // Changing the value of 'isExpanded' when an item is tapped in the List
          setState(() {
            isExpanded = !isExpanded;
          });
        },
        // AnimatedContainer for slowing down the changing
        child: AnimatedContainer(
          duration: Duration(milliseconds: 150),
          // Changing the width and height
          height: isExpanded ? 250 : 150,
          width: isExpanded ? 250 : 150,
          // Decoration Portion of the Container
          decoration: BoxDecoration(
              color: Colors.blue, borderRadius: BorderRadius.circular(15.0)),
        ),
      ),
    );
  }
}

于 2020-10-21T12:14:57.723 回答