RenderFlex 底部溢出了 676 像素。在 SingleChildScrollView 中
\nWidget dashboard(context){\n return AnimatedPositioned(\n duration: duration,\n top:0,\n bottom:0,\n left:isCollapsed ? 0 : 0.6 * screenWidth,\n right:isCollapsed ? 0 : -0.2 * screenWidth,\n child: ScaleTransition(\n scale: _scaleAnimation,\n child: Material(\n animationDuration: duration ,\n borderRadius: BorderRadius.all(\n Radius.circular(40),\n ),\n elevation: 8,\n color:backgroundColor,\n child: Column(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: <Widget>[\n Container(\n padding: const EdgeInsets.only(left: 16, right: 16, top: 48),\n child: Row(\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n mainAxisSize: MainAxisSize.max,\n children:[\n InkWell(\n child: Icon(\n Icons.menu,\n color: Colors.white\n ),\n onTap: (){\n setState(() {\n if(isCollapsed)\n _controller.forward();\n else\n _controller.reverse();\n\n isCollapsed = !isCollapsed;\n });\n },\n ),\n Text(\n " T\xc3\xa9cnico",\n style: TextStyle(\n fontSize: 24,\n color: Colors.white,\n ),\n ),\n Icon(\n Icons.settings,\n color: Colors.white,\n ),\n ]),\n ),\n Container(\n child: SingleChildScrollView(\n scrollDirection: Axis.vertical,\n physics: ClampingScrollPhysics(),\n child: Column(\n children: <Widget>[\n SizedBox(\n height: 5,\n ),\n SizedBox(\n height:20 ,\n ),\n Text("Chamados",\n style: TextStyle(\n color: Colors.white,\n fontSize: 20,\n ) ,\n ),\n SizedBox(\n height:5 ,\n ),\n ListView.separated(\n shrinkWrap: true,\n itemBuilder: (context,index){\n return ListTile(\n title: Text("Falta de Sinal"),\n subtitle: Text("Jo\xc3\xa3o"),\n trailing: Text("20mb"),\n );\n }, separatorBuilder: (context,index){\n return Divider(\n height: 16,\n );\n }, itemCount: 16),\n ],\n ),\n ),\n ),\n ],\n ),\n ),\n ),\n );\n }\n
Run Code Online (Sandbox Code Playgroud)\n
小智 7
如果您使用SingleChildScrollView
内部列或行,则用Expanded
小部件将其包装起来。
e.g. Column(
childreen[
Expanded(
child : SingleChildScrollView(
// your code ...
),
]),
Run Code Online (Sandbox Code Playgroud)
或者您可以提供容器的高度。
e.g. -> Container(
height : 300.0,
child : SingleChildScrollView(
// your code ...
),
),
Run Code Online (Sandbox Code Playgroud)
快乐编码...:)
用Container包裹ListView.separated并添加约束,设置maxHeight即可,如下图
代码片段
\n\nContainer(\n constraints: BoxConstraints(\n maxHeight: 300.0,\n ),\n child: ListView.separated(\n shrinkWrap: true,\n itemBuilder: (context, index) {\n return ListTile(\n title: Text("Falta de Sinal"),\n subtitle: Text("Jo\xc3\xa3o"),\n trailing: Text("20mb"),\n );\n },\n separatorBuilder: (context, index) {\n return Divider(\n height: 16,\n );\n },\n itemCount: 16),\n ),\n
Run Code Online (Sandbox Code Playgroud)\n\n完整的测试代码
\n\n import \'package:flutter/material.dart\';\n\nvoid main() => runApp(MyApp());\n\nclass MyApp extends StatelessWidget {\n // This widget is the root of your application.\n @override\n Widget build(BuildContext context) {\n return MaterialApp(\n title: \'Flutter Demo\',\n theme: ThemeData(\n // This is the theme of your application.\n //\n // Try running your application with "flutter run". You\'ll see the\n // application has a blue toolbar. Then, without quitting the app, try\n // changing the primarySwatch below to Colors.green and then invoke\n // "hot reload" (press "r" in the console where you ran "flutter run",\n // or simply save your changes to "hot reload" in a Flutter IDE).\n // Notice that the counter didn\'t reset back to zero; the application\n // is not restarted.\n primarySwatch: Colors.blue,\n ),\n home: MyHomePage(title: \'Flutter Demo Home Page\'),\n );\n }\n}\n\nclass MyHomePage extends StatefulWidget {\n MyHomePage({Key key, this.title}) : super(key: key);\n\n // This widget is the home page of your application. It is stateful, meaning\n // that it has a State object (defined below) that contains fields that affect\n // how it looks.\n\n // This class is the configuration for the state. It holds the values (in this\n // case the title) provided by the parent (in this case the App widget) and\n // used by the build method of the State. Fields in a Widget subclass are\n // always marked "final".\n\n final String title;\n\n @override\n _MyHomePageState createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n int _counter = 0;\n\n void _incrementCounter() {\n setState(() {\n // This call to setState tells the Flutter framework that something has\n // changed in this State, which causes it to rerun the build method below\n // so that the display can reflect the updated values. If we changed\n // _counter without calling setState(), then the build method would not be\n // called again, and so nothing would appear to happen.\n _counter++;\n });\n }\n\n @override\n Widget build(BuildContext context) {\n // This method is rerun every time setState is called, for instance as done\n // by the _incrementCounter method above.\n //\n // The Flutter framework has been optimized to make rerunning build methods\n // fast, so that you can just rebuild anything that needs updating rather\n // than having to individually change instances of widgets.\n return Scaffold(\n appBar: AppBar(\n // Here we take the value from the MyHomePage object that was created by\n // the App.build method, and use it to set our appbar title.\n title: Text(widget.title),\n ),\n body: Center(\n // Center is a layout widget. It takes a single child and positions it\n // in the middle of the parent.\n child: Column(\n // Column is also a layout widget. It takes a list of children and\n // arranges them vertically. By default, it sizes itself to fit its\n // children horizontally, and tries to be as tall as its parent.\n //\n // Invoke "debug painting" (press "p" in the console, choose the\n // "Toggle Debug Paint" action from the Flutter Inspector in Android\n // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)\n // to see the wireframe for each widget.\n //\n // Column has various properties to control how it sizes itself and\n // how it positions its children. Here we use mainAxisAlignment to\n // center the children vertically; the main axis here is the vertical\n // axis because Columns are vertical (the cross axis would be\n // horizontal).\n mainAxisAlignment: MainAxisAlignment.center,\n children: <Widget>[\n dashboard(context),\n Text(\n \'You have pushed the button this many times:\',\n ),\n Text(\n \'$_counter\',\n style: Theme.of(context).textTheme.display1,\n ),\n ],\n ),\n ),\n floatingActionButton: FloatingActionButton(\n onPressed: _incrementCounter,\n tooltip: \'Increment\',\n child: Icon(Icons.add),\n ), // This trailing comma makes auto-formatting nicer for build methods.\n );\n }\n\n Widget dashboard(context) {\n return Container(\n child: SingleChildScrollView(\n scrollDirection: Axis.vertical,\n physics: ClampingScrollPhysics(),\n child: Column(\n children: <Widget>[\n SizedBox(\n height: 5,\n ),\n SizedBox(\n height: 20,\n ),\n Text(\n "Chamados",\n style: TextStyle(\n color: Colors.black,\n fontSize: 20,\n ),\n ),\n SizedBox(\n height: 5,\n ),\n Container(\n constraints: BoxConstraints(\n maxHeight: 300.0,\n ),\n child: ListView.separated(\n shrinkWrap: true,\n itemBuilder: (context, index) {\n return ListTile(\n title: Text("Falta de Sinal"),\n subtitle: Text("Jo\xc3\xa3o"),\n trailing: Text("20mb"),\n );\n },\n separatorBuilder: (context, index) {\n return Divider(\n height: 16,\n );\n },\n itemCount: 16),\n ),\n ],\n ),\n ),\n );\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n\n
归档时间: |
|
查看次数: |
5663 次 |
最近记录: |