Flutter 展开或灵活添加白色底部
更新Flutter 展开或灵活添加白色底部,flutter,dart,widget,Flutter,Dart,Widget,更新 添加了最小代码 我想在scrollview中显示长文本。 最多红线文本可滚动 我试过: 使用灵活的::相同的结果 包装在容器中::它使文本全屏且不可滚动 代码 如果我尝试增加flex属性,它将开始与上面的小部件重叠 谢谢你 完整代码 import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; void main() { runApp(
添加了最小代码
我想在scrollview中显示长文本。
最多红线文本可滚动
我试过:
使用灵活的::相同的结果
包装在容器中::它使文本全屏且不可滚动 代码 如果我尝试增加
flex
属性,它将开始与上面的小部件重叠
谢谢你完整代码
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
backgroundColor: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Color(0xff010409),
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: TextField(
// controller: _uri,
decoration: InputDecoration(
hintText: 'Search', prefixIcon: Icon(Icons.search)),
),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {
},
child: Icon(Icons.search),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
body: SafeArea(
child: Column(children: <Widget>[
Flexible(
child: Text(
'abc',
style: TextStyle(
color: Color(0xff58a6ff), fontWeight: FontWeight.bold, fontSize: 30),
)),
new Expanded(
flex:2,
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(
'Big String',
style: TextStyle(color: Colors.white, fontSize: 24),
)),
),
])),
);
}
}
导入'dart:convert';
进口“包装:颤振/材料.省道”;
将“package:http/http.dart”导入为http;
void main(){
runApp(MyApp());
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
背景颜色:Colors.blue,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
var size=MediaQuery.of(context).size;
返回脚手架(
背景颜色:颜色(0xff010409),
resizeToAvoidBottomInset:false,
appBar:appBar(
标题:文本字段(
//控制器:_uri,
装饰:输入装饰(
hintText:“搜索”,前缀:Icon(Icons.Search)),
),
行动:[
扁平按钮(
textColor:Colors.white,
已按下:(){
},
子:图标(Icons.search),
形状:圆形顺序(边:边框边(颜色:Colors.transparent)),
),
],
),
正文:安全区(
子项:列(子项:[
灵活的(
子:文本(
“abc”,
样式:TextStyle(
颜色:颜色(0xff58a6ff),fontWeight:fontWeight.bold,fontSize:30),
)),
新扩展(
弹性:2,
子:新的SingleChildScrollView(
滚动方向:轴垂直,
子:文本(
"大弦",,
样式:TextStyle(颜色:Colors.white,字体大小:24),
)),
),
])),
);
}
}
将文本
小部件包装成列
适合我,如下所示:
。。。
SingleChildScrollView(
滚动方向:轴垂直,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.center,
孩子们[
文本(“非常长的文本”,
样式:TextStyle(颜色:Colors.black,字体大小:24),
),
]
)
...
我不确定您是否需要在
SingleChildScrollView
上方展开小部件,将文本
小部件包装成列
,如下所示:
。。。
SingleChildScrollView(
滚动方向:轴垂直,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.center,
孩子们[
文本(“非常长的文本”,
样式:TextStyle(颜色:Colors.black,字体大小:24),
),
]
)
...
我不确定您是否需要在SingleChildScrollView
上扩展这个代码片段对我来说很好
更新:
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Color(0xff010409),
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: TextField(
// controller: _uri,
decoration: InputDecoration(
hintText: 'Search', prefixIcon: Icon(Icons.search)),
),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {},
child: Icon(Icons.search),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
body: SafeArea(
child: Column(children: <Widget>[
//Removed Flexible Widget
Text(
'abc',
style: TextStyle(
color: Color(0xff58a6ff),
fontWeight: FontWeight.bold,
fontSize: 30),
),
new Expanded(
// flex: 2, //commented flex here for taking the whole available space.
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(
"""A Long Long String Here...""",
style: TextStyle(color: Colors.white, fontSize: 24),
)),
),
])),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
var size=MediaQuery.of(context).size;
返回脚手架(
背景颜色:颜色(0xff010409),
resizeToAvoidBottomInset:false,
appBar:appBar(
标题:文本字段(
//控制器:_uri,
装饰:输入装饰(
hintText:“搜索”,前缀:Icon(Icons.Search)),
),
行动:[
扁平按钮(
textColor:Colors.white,
按下:(){},
子:图标(Icons.search),
形状:圆形顺序(边:边框边(颜色:Colors.transparent)),
),
],
),
正文:安全区(
子项:列(子项:[
//删除了灵活的小部件
正文(
“abc”,
样式:TextStyle(
颜色:颜色(0xff58a6ff),
fontWeight:fontWeight.bold,
尺寸:30),,
),
新扩展(
//flex:2,//在这里对flex进行了注释,以占用整个可用空间。
子:新的SingleChildScrollView(
滚动方向:轴垂直,
子:文本(
“这里有一根长字符串…”,
样式:TextStyle(颜色:Colors.white,字体大小:24),
)),
),
])),
);
}
}
在上面的代码中,用长文本替换一个很长的字符串
正如@AK-23所指出的,您确定需要在SingleChildScrollView
上扩展小部件吗
如果是,则粘贴完整的代码,以便我们能够解决问题
编辑:
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Color(0xff010409),
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: TextField(
// controller: _uri,
decoration: InputDecoration(
hintText: 'Search', prefixIcon: Icon(Icons.search)),
),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {},
child: Icon(Icons.search),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
body: SafeArea(
child: Column(children: <Widget>[
//Removed Flexible Widget
Text(
'abc',
style: TextStyle(
color: Color(0xff58a6ff),
fontWeight: FontWeight.bold,
fontSize: 30),
),
new Expanded(
// flex: 2, //commented flex here for taking the whole available space.
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(
"""A Long Long String Here...""",
style: TextStyle(color: Colors.white, fontSize: 24),
)),
),
])),
);
}
}
我已经从文本
中删除了Flexible
小部件,并且注释了扩展的
小部件的Flexible
小部件,并且code
开始工作。这段代码对我来说很好
更新:
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Color(0xff010409),
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: TextField(
// controller: _uri,
decoration: InputDecoration(
hintText: 'Search', prefixIcon: Icon(Icons.search)),
),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {},
child: Icon(Icons.search),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
body: SafeArea(
child: Column(children: <Widget>[
//Removed Flexible Widget
Text(
'abc',
style: TextStyle(
color: Color(0xff58a6ff),
fontWeight: FontWeight.bold,
fontSize: 30),
),
new Expanded(
// flex: 2, //commented flex here for taking the whole available space.
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(
"""A Long Long String Here...""",
style: TextStyle(color: Colors.white, fontSize: 24),
)),
),
])),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_米宏