List 建立一个列表<;扁平按钮>;使用火基
我正在构建一个按钮列表,使用Firebase为每个按钮命名,但我的代码在引用小部件“\u getButtonBar”时出现了此错误:“参数类型‘Future’不能分配给参数类型‘list’”。小部件也应该是未来的吗?有人知道少了什么吗List 建立一个列表<;扁平按钮>;使用火基,list,firebase,flutter,dart,flatbutton,List,Firebase,Flutter,Dart,Flatbutton,我正在构建一个按钮列表,使用Firebase为每个按钮命名,但我的代码在引用小部件“\u getButtonBar”时出现了此错误:“参数类型‘Future’不能分配给参数类型‘list’”。小部件也应该是未来的吗?有人知道少了什么吗 class ThemesList extends StatelessWidget { Future<List<FlatButton>> _getButtonBar(context) async { List<FlatBut
class ThemesList extends StatelessWidget {
Future<List<FlatButton>> _getButtonBar(context) async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
return _list1;
}
@override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: ButtonBar(
children: _getButtonBar(
context), //<-- Here it points out the error.
alignment: MainAxisAlignment.center,
),
),
),
],
),
);
}
}
类主题列表扩展了无状态小部件{
Future\u getButtonBar(上下文)异步{
列表_list1=[];
tot=wait callReadTotal();//接收长度以进行循环。
getListCauss();//调用Firebase为child:Text使用arrCauss=List()
对于(int i=1;i{
(一),
导航器。推(
上下文
MaterialPage路由(生成器:(上下文)=>CausesList()),
),
},
子:文本(
原因[i],
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:20,
fontFamily:“Balsamiq_Sans”,
),
),
),
);
}
返回列表1;
}
@凌驾
小部件构建(构建上下文){
返回平台
?CupertinoPageScaffold(子项:null)
:脚手架(
appBar:appBar(
标题:正文(
“ICare”,
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:40,
fontFamily:“Balsamiq_Sans”,
fontWeight:fontWeight.w500,
),
),
flexibleSpace:图像(
image:AssetImage('assets/images/solidariedade.png'),
颜色:颜色。来自RGBO(255、200、200、0.45),
colorBlendMode:BlendMode.modulate,
适合:BoxFit.cover,
),
),
主体:堆栈(
儿童:[
容器(
子:SingleChildScrollView(
滚动方向:轴垂直,
孩子:巴顿巴(
儿童:_getButtonBar(
上下文),//您的问题可以通过两个选项解决
通过使用StatefulWidget
import 'package:flutter/material.dart';
class ThemesList extends StatefulWidget {
@override
_ThemesListState createState() => _ThemesListState();
}
class _ThemesListState extends State<ThemesList> {
List<FlatButton> _buttonBar = [];
@override
void initState() {
_getButtonBar();
super.initState();
}
_getButtonBar() async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
_buttonBar = _list1;
setState(() {});
}
@override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: ButtonBar(
children: _buttonBar,
alignment: MainAxisAlignment.center,
),
),
),
],
),
);
}
}
导入“包装:颤振/材料.省道”;
类主题列表扩展StatefulWidget{
@凌驾
_ThemesListState createState()=>\u ThemesListState();
}
类_ThemesListState扩展状态{
列表_buttonBar=[];
@凌驾
void initState(){
_getButtonBar();
super.initState();
}
_getButtonBar()异步{
列表_list1=[];
tot=wait callReadTotal();//接收长度以进行循环。
getListCauss();//调用Firebase为child:Text使用arrCauss=List()
对于(int i=1;i{
(一),
导航器。推(
上下文
MaterialPage路由(生成器:(上下文)=>CausesList()),
),
},
子:文本(
原因[i],
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:20,
fontFamily:“Balsamiq_Sans”,
),
),
),
);
}
_按钮栏=_列表1;
setState((){});
}
@凌驾
小部件构建(构建上下文){
返回平台
?CupertinoPageScaffold(子项:null)
:脚手架(
appBar:appBar(
标题:正文(
“ICare”,
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:40,
fontFamily:“Balsamiq_Sans”,
fontWeight:fontWeight.w500,
),
),
flexibleSpace:图像(
image:AssetImage('assets/images/solidariedade.png'),
颜色:颜色。来自RGBO(255、200、200、0.45),
colorBlendMode:BlendMode.modulate,
适合:BoxFit.cover,
),
),
主体:堆栈(
儿童:[
容器(
子:SingleChildScrollView(
滚动方向:轴垂直,
孩子:巴顿巴(
孩子们:_buttonBar,
对齐:MainAxisAlignment.center,
),
),
),
],
),
);
}
}
使用FutureBuilder
import 'package:flutter/material.dart';
class ThemesList extends StatelessWidget {
Future<List<FlatButton>> _getButtonBar(context) async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
return _list1;
}
@override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: FutureBuilder<List<FlatButton>>(
future: _getButtonBar(context),
builder: (context,
AsyncSnapshot<List<FlatButton>> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Text('Loading....');
break;
default:
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
else
return ButtonBar(
children: snapshot.data,
alignment: MainAxisAlignment.center,
);
}
}),
),
),
],
),
);
}
}
导入“包装:颤振/材料.省道”;
类主题列表扩展了无状态小部件{
Future\u getButtonBar(上下文)异步{
列表_list1=[];
tot=wait callReadTotal();//接收长度以进行循环。
getListCauss();//调用Firebase为child:Text使用arrCauss=List()
对于(int i=1;i{
(一),
导航器。推(
上下文
MaterialPage路由(生成器:(上下文)=>CausesList()),
),
},
子:文本(
原因[i],
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:20,
fontFamily:“Balsamiq_Sans”,
),
),
),
);
}
返回列表1;
}
@凌驾
小部件构建(构建上下文){
返回平台
?CupertinoPageScaffold(子项:null)
:脚手架(
appBar:appBar(
标题:正文(
“ICare”,
样式:TextStyle(
颜色:颜色。来自RGBO(150,1,1,1),
尺寸:40,
fontFamily:“Balsamiq_Sans”,
fontWeight:fontWeight.w500,
),
),
flexibleSpace:图像(
image:AssetImage('assets/images/solidariedade.png'),
颜色:颜色。来自RGBO(255、200、200、0.45),
colorBlendMode:BlendMode.modulate,
适合:BoxFit.cover,
),
),