How to make Expandable card?

前端 未结 3 997
攒了一身酷
攒了一身酷 2021-01-04 20:50

I am new to flutter and I want to make a list of cards like this.

I tried to Understand the original Project but I am not able to figure out.

I just

3条回答
  •  悲哀的现实
    2021-01-04 21:24

    Here is an example of what I said in the comments on your question:

    It contains a Card with a Container which contains a height, the height is updated when the Card is tapped because of the InkWell's onTap event, the onTap calls the setState() function to update the widgets, with the new height of the Card.

       class MyApp extends StatefulWidget {
          double oldheight = 100.0;
          double newheight = 200.0;
          double height = 200.0;
    
          @override
          Widget build(BuildContext context) {
            final title = 'Basic List';
    
            return MaterialApp(
              title: title,
              home: Scaffold(
                appBar: AppBar(
                  title: Text(title),
                ),
                body: ListView(
                  children: [
                    InkWell(
                      onTap: () {
                        setState(() {
                          if (height == oldheight) {
                            height = newheight;
                          }
                          else{
                            height = oldheight;
                          }
                        });
                      },
                      child: Card(
                        child:Container(height: height,),
                      ),
                    ),
                  ],
                ),
              ),
            );
          }
    

    This isn't tested yet...

提交回复
热议问题