【问题标题】:Flutter I want to design the interface like this, can you guys help me? I am designing an about page but I am having problemsFlutter 我想设计这样的界面,你们能帮帮我吗?我正在设计一个关于页面,但我遇到了问题
【发布时间】:2020-01-18 21:21:52
【问题描述】:

我刚刚学习并开始尝试设计一个关于页面。我在颤动的卡片上有困难。我需要一个完整的演示板来参考下一个问题。

【问题讨论】:

标签: ios android-layout mobile flutter layout


【解决方案1】:

你可以使用扩展包

完整代码

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Expandable Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() {
    return MyHomePageState();
  }
}

class MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("About DTC"),
      ),
      body: ListView(
        children: <Widget>[
          Text(
            loremIpsum,
            softWrap: true,
            overflow: TextOverflow.fade,
          ),
          Card1(),
          Card2(),
        ],
      ),
    );
  }
}

const loremIpsum =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

class Card1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ExpandableNotifier(
        child: ScrollOnExpand(
      scrollOnExpand: false,
      scrollOnCollapse: true,
      child: Padding(
        padding: const EdgeInsets.all(10),
        child: Card(
          clipBehavior: Clip.antiAlias,
          child: Column(
            children: <Widget>[
              ScrollOnExpand(
                scrollOnExpand: true,
                scrollOnCollapse: false,
                child: ExpandablePanel(
                  tapHeaderToExpand: true,
                  tapBodyToCollapse: true,
                  headerAlignment: ExpandablePanelHeaderAlignment.center,
                  header: Padding(
                      padding: EdgeInsets.all(10),
                      child: Text(
                        "Service",
                        style: Theme.of(context).textTheme.body2,
                      )),
                  collapsed:
                      Container(), //Text('Service', softWrap: true, maxLines: 2, overflow: TextOverflow.ellipsis,),
                  expanded: Column(
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          ),
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          )
                        ],
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          ),
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          )
                        ],
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          ),
                          Expanded(
                            child: Column(children: <Widget>[
                              ListTile(title: Text('Item ')),
                            ]),
                          )
                        ],
                      ),
                    ],
                  ),
                  builder: (_, collapsed, expanded) {
                    return Padding(
                      padding: EdgeInsets.only(left: 1, right: 1, bottom: 1),
                      child: Expandable(
                        collapsed: collapsed,
                        expanded: expanded,
                        crossFadePoint: 0,
                      ),
                    );
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }
}

class Card2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ExpandableNotifier(
        child: ScrollOnExpand(
      scrollOnExpand: false,
      scrollOnCollapse: true,
      child: Padding(
        padding: const EdgeInsets.all(10),
        child: Card(
          clipBehavior: Clip.antiAlias,
          child: Column(
            children: <Widget>[
              ScrollOnExpand(
                scrollOnExpand: true,
                scrollOnCollapse: false,
                child: ExpandablePanel(
                  tapHeaderToExpand: true,
                  tapBodyToCollapse: true,
                  headerAlignment: ExpandablePanelHeaderAlignment.center,
                  header: Padding(
                      padding: EdgeInsets.all(10),
                      child: Text(
                        "Contact",
                        style: Theme.of(context).textTheme.body2,
                      )),
                  collapsed:
                      Container(), //Text("Contact", softWrap: true, maxLines: 2, overflow: TextOverflow.ellipsis,),
                  expanded: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Padding(
                          padding: EdgeInsets.only(bottom: 10),
                          child: Text(
                            'Address : 5F',
                            softWrap: true,
                            overflow: TextOverflow.fade,
                          )),
                    ],
                  ),
                  builder: (_, collapsed, expanded) {
                    return Padding(
                      padding: EdgeInsets.only(left: 1, right: 1, bottom: 1),
                      child: Expandable(
                        collapsed: collapsed,
                        expanded: expanded,
                        crossFadePoint: 0,
                      ),
                    );
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-24
    • 2022-11-14
    • 2011-01-28
    • 2011-01-24
    • 2021-08-14
    • 2021-08-18
    • 2022-12-12
    • 2021-04-07
    相关资源
    最近更新 更多