使用mysql计算颤振总价
嘿,伙计们,我需要一些帮助,我无法计算结帐过程中的总价,我正在从我的mysql服务器获取数据。我已经尝试了很多事情,但我无法解决这个问题。有人能帮我吗?使用mysql计算颤振总价,mysql,flutter,Mysql,Flutter,嘿,伙计们,我需要一些帮助,我无法计算结帐过程中的总价,我正在从我的mysql服务器获取数据。我已经尝试了很多事情,但我无法解决这个问题。有人能帮我吗? returnTotalAmount函数由BottomBar小部件包装,它只是UI,因此我没有共享它 这是我包装的小部件的代码 home: new Scaffold( appBar: new AppBar(title: const Text('MySQL Images Text')), body: new Ce
returnTotalAmount函数由BottomBar小部件包装,它只是UI,因此我没有共享它 这是我包装的小部件的代码
home: new Scaffold(
appBar: new AppBar(title: const Text('MySQL Images Text')),
body: new Center(
//FutureBuilder is a widget that builds itself based on the latest snapshot
// of interaction with a Future.
child: new FutureBuilder<List<Employee>>(
future: Services.getEmployees(),
//we pass a BuildContext and an AsyncSnapshot object which is an
//Immutable representation of the most recent interaction with
//an asynchronous computation.
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Employee> _employee = snapshot.data;
Services.getEmployees();
return Scaffold(
body: SafeArea(
child: CustomListView(_employee),
),
bottomNavigationBar: BottomBar(_employee),
);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
String returnTotalAmount(List<Employee> _employee) {
double totalAmount = 0.0;
for (int i = 0; i < _employee.length; i++) {
totalAmount = totalAmount + _employee[i].price * _employee[i].quantity;
}
return totalAmount.toRadixString(2);
}
Container totalAmount(List<Employee> _employee) {
return Container(
margin: EdgeInsets.only(right: 10),
padding: EdgeInsets.all(25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
" Total:",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300),
),
Text(
"\$${returnTotalAmount(_employee)}",
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 28),
),
],
),
);
}
主页:新脚手架(
appBar:new appBar(标题:常量文本('MySQL图像文本')),
正文:新中心(
//FutureBuilder是一个基于最新快照构建自身的小部件
//与未来的互动。
孩子:新未来建设者(
future:Services.getEmployees(),
//我们传递一个BuildContext和一个AsyncSnapshot对象,它是
//最近与的交互的不可变表示
//异步计算。
生成器:(上下文,快照){
if(snapshot.hasData){
列表_employee=snapshot.data;
Services.getEmployees();
返回脚手架(
正文:安全区(
子项:CustomListView(_employee),
),
bottomNavigationBar:BottomBar(_员工),
);
}else if(snapshot.hasrerror){
返回文本(“${snapshot.error}”);
}
字符串returnTotalAmount(列表\u员工){
双倍总额=0.0;
对于(int i=0;i<\u employee.length;i++){
totalAmount=totalAmount+\员工[i]。价格*\员工[i]。数量;
}
返回totalAmount.toRadixString(2);
}
集装箱总金额(列表_员工){
返回容器(
页边距:仅限边集(右:10),
填充:边缘设置。全部(25),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
正文(
“总数:”,
样式:TextStyle(fontSize:25,fontWeight:fontWeight.w300),
),
正文(
“\${returnTotalAmount(\u employee)}”,
样式:TextStyle(fontWeight:fontWeight.w700,fontSize:28),
),
],
),
);
}
这是我的结账页面,我应该计算一下价格
这是我的员工页面
班级员工{
字符串id;
字符串名;
串价;
字符串路径;
串数;
Employee({this.id,this.firstName,this.price,this.path,this.quantity});
factory Employee.fromjson(映射json){
返回员工(
id:json['id']作为字符串,
firstName:json['first_name']作为字符串,
price:json['price']作为字符串,
path:json['path']作为字符串,
数量:json['quantity']作为字符串,
);
}}
这是我从数据库获取数据的api代码
static Future<List<Employee>> getEmployees() async {
try {
var map = Map<String, dynamic>();
map['action'] = _GET_ALL_ACTION;
final response = await http.post(ROOT, body: map);
print('getEmployees Response: ${response.body}');
if (200 == response.statusCode) {
List<Employee> list = parseResponse(response.body);
return list;
} else {
return List<Employee>();
}
} catch (e) {
return List<Employee>(); // return an empty list on exception/error
}
}
static Future getEmployees()异步{
试一试{
var map=map();
map['action']=\u获取所有\u操作;
最终响应=等待http.post(根,主体:map);
打印('getEmployees响应:${Response.body}');
if(200==响应.状态码){
List=parseResponse(response.body);
退货清单;
}否则{
返回列表();
}
}捕获(e){
return List();//在异常/错误时返回空列表
}
}
字符串returnTotalAmount(列出员工){
双倍总额=0.0
for (int i = 0; i < _employee.length; i++) {
totalAmount = totalAmount + (double.parse(_employee[i].price)*double.parse(_employee[i].quantity));
}
return totalAmount.toString();
}
for(int i=0;i<\u employee.length;i++){
totalAmount=totalAmount+(double.parse(_employee[i].price)*double.parse(_employee[i].quantity));
}
返回totalAmount.toString();
}
<代码>发布你的代码,它显示了你如何使用“RetrutoToMultuple”函数已经更新它。你可以检查你的键盘是否能产生完整的停止和大写字母,考虑相应地修改你的问题。使用<代码> String总计=返回ToTrimeUnter(SuffEngress);<代码> > <代码>总计()
然后在文本中使用总字符串,如文本(\$$total”)
for (int i = 0; i < _employee.length; i++) {
totalAmount = totalAmount + (double.parse(_employee[i].price)*double.parse(_employee[i].quantity));
}
return totalAmount.toString();
}