- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在产品添加成功后显示一个对话框,但是当我点击“添加到购物车”按钮时,我收到了图像中的那种类型的错误。
这个对话框想显示使用httpException,在我使用这个httpExcetion的product_detailpage.dart页面中我使用虚线。
import 'dart:convert';
import 'package:hospital/CartPage/Cart_Api/cart_http_exception.dart';
import 'package:hospital/customApiVariable.dart';
import 'package:http/http.dart' as http;
Future add_to_cart_fn(
String quantity, String plistId, String uid, String sid) async {
var url = Uri.parse(
'$ecommerceBaseUrl/addToCartApi.php?a2rTokenKey=$a2rTokenKey&action=addToCart&uid=60daaedd3b9f8751161');
print('add_to_cart_url:' + url.toString());
final response = await http.post(url, headers: {
"Accept": "Application/json"
}, body: {
"quantity": quantity,
"plistId": plistId,
"uid": uid,
"sid": sid,
});
print("ae" + response.body);
final convertderDatatoJson = jsonDecode(response.body);
try {
if (convertderDatatoJson['status'] == "true") {
print('status' + convertderDatatoJson['status']);
print('msg' + convertderDatatoJson['msg']);
throw HttpException(convertderDatatoJson['msg']);
}
} catch (e) {
throw e;
}
return convertderDatatoJson;
}
这是我的 httpException.dart 页面
class HttpException implements Exception {
final msg;
HttpException(this.msg);
@override
String toString() {
// TODO: implement toString
return msg;
}
}
这是我的 product_detailPage.dart 页面,
import 'dart:convert';
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/material.dart';
import 'package:hospital/CartPage/Cart_Api/cart_api.dart';
import 'package:hospital/CartPage/Cart_Api/cart_http_exception.dart';
import 'package:hospital/CartPage/pages/cartPage.dart';
import 'package:hospital/Drawer/dropdown_menu.dart';
import 'package:hospital/ProductDetailsPage/product_detailPage.dart';
import 'package:hospital/ProductDetailsPage/related_product_page.dart';
import 'package:hospital/SecondSection/Medicine/medicine_page.dart';
import 'package:hospital/constant.dart';
import 'package:hospital/customApiVariable.dart';
import 'package:http/http.dart' as http;
import 'package:line_icons/line_icons.dart';
import 'package:provider/provider.dart';
class DetailPage extends StatefulWidget {
final plistId;
const DetailPage({Key key, this.plistId}) : super(key: key);
@override
_DetailPageState createState() => _DetailPageState();
}
class _DetailPageState extends State<DetailPage> {
final GlobalKey<FormState> _formKey = GlobalKey();
int quantity = 1;
var response;
var detailPageApi;
@override
void initState() {
super.initState();
fetchData(widget.plistId);
}
fetchData(var consultWithDoctor) async {
a2rTokenKey=carpet1234');
var api = Uri.parse(
'$ecommerceBaseUrl/productListApi.php?a2rTokenKey=$a2rTokenKey&plistId=${widget.plistId}');
response = await http.get(
api,
);
print("detailPageApi " + api.toString());
print("detailPageBody " + response.body);
// in double quotes drink is key value of json
detailPageApi = jsonDecode(response.body);
print("detailPagelist " + detailPageApi.toString());
// return doctorDetailsApi;
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: kGreen,
title: Text(
"Details",
style: TextStyle(fontStyle: FontStyle.italic),
),
actions: [
IconButton(
icon: Icon(Icons.shopping_cart),
// onPressed: () => print("open cart"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Cartpage()),
);
},
),
DropDownMenu(),
],
),
body: Container(
child: response != null
? ListView.builder(
// itemCount: categoryApi.length.clamp(0, 3),//THis is for showed minimun length of item listview.builder flutter
itemCount: detailPageApi.length.clamp(0, 1),
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, index) {
var details = detailPageApi[index];
if (details['num'] == 0) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.white,
),
);
}
return Column(
children: <Widget>[
Hero(
tag: "1",
child: SizedBox(
height: 300.0,
width: 300.0,
child: Carousel(
boxFit: BoxFit.cover,
autoplay: false,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 800),
dotSize: 6.0,
dotIncreasedColor: Colors.black,
dotBgColor: Colors.transparent,
// dotPosition: DotPosition.topRight,
dotVerticalPadding: 10.0,
showIndicator: true,
indicatorBgPadding: 7.0,
images: [
NetworkImage(details['pImgImg']),
],
),
),
),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.only(left: 20, right: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Name :",
style: TextStyle(
fontSize: 18,
height: 1.5,
fontWeight: FontWeight.w500),
),
SizedBox(
width: 20,
),
Flexible(
child: Text(
// widget.details,
details['productName'],
style: TextStyle(
fontSize: 17,
height: 1.5,
fontWeight: FontWeight.w500),
),
),
],
),
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(left: 20, right: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Details :",
style: TextStyle(
fontSize: 18,
height: 1.5,
fontWeight: FontWeight.w500),
),
SizedBox(
width: 20,
),
Flexible(
child: Text(
// widget.details,
details['productDescription'],
style: TextStyle(
fontSize: 17,
height: 1.5,
fontWeight: FontWeight.w500),
),
),
],
),
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(left: 20, right: 20),
child: Row(
children: <Widget>[
Text(
"Price :",
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
SizedBox(
width: 20,
),
Row(
children: <Widget>[
Text(
// "Rs " + widget.pPromotionPrice,
"Rs 55.0",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500),
),
SizedBox(
width: 20,
),
Text(
// "Rs " + widget.pPrice,
"Rs 100",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
// color: warning,
decoration: TextDecoration.lineThrough),
)
],
)
],
),
),
SizedBox(
height: 25,
),
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Row(
children: <Widget>[
Text(
"Qty :",
style: TextStyle(
fontSize: 17, fontWeight: FontWeight.w500),
),
SizedBox(
width: 20,
),
Row(
children: <Widget>[
InkWell(
onTap: () {
if (quantity > 1) {
setState(() {
quantity = --quantity;
});
}
// minus here
},
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
// border: Border.all(color: primary),
shape: BoxShape.circle),
child: Icon(
LineIcons.minus,
size: 15,
),
),
),
SizedBox(
width: 15,
),
Text(
quantity.toString(),
style: TextStyle(fontSize: 16),
),
SizedBox(
width: 15,
),
InkWell(
onTap: () {
setState(() {
quantity = ++quantity;
});
// minus here
},
child: Container(
width: 25,
height: 25,
decoration: BoxDecoration(
// border: Border.all(color: primary),
shape: BoxShape.circle),
child: Icon(
LineIcons.plus,
size: 15,
),
),
),
],
)
],
),
),
SizedBox(
height: 50,
),
InkWell(
onTap: () async {
---------------------------------------------
//here show my msg using dialog box
try {} on HttpException catch (e) {
print('hiii');
var errorMessage = 'Authentication Failed';
if (e.toString().contains(
'Product Succesfully Added to Cart')) {
errorMessage =
'Product Succesfully Added to Cart';
print(errorMessage);
_showerrorDialog(errorMessage);
}
} catch (error) {
var errorMessage = 'Please try again later';
_showerrorDialog(errorMessage);
}
------------------------------------------------
var qty = quantity.toString();
var plistId = widget.plistId;
print('pplistid' + plistId);
var uid = var_uid.toString();
var sid = var_sid.toString();
print('uuid' + uid);
print('ssid' + sid);
var response =
await add_to_cart_fn(qty, plistId, uid, sid);
print("rsp: " + response['status']);
},
// },
child: Padding(
padding: EdgeInsets.only(left: 20, right: 20),
child: Container(
height: 45,
width: double.infinity,
decoration: BoxDecoration(
color: kGreen,
borderRadius: BorderRadius.circular(30)),
child: Center(
child: Text(
"ADD TO CART",
style: TextStyle(
color: kWhite,
fontSize: 20,
),
),
),
),
),
),
SizedBox(height: 20.0),
// SomeMedicinePage(),
RelatedProductPage(plistId: widget.plistId)
],
);
})
: Center(
child: CircularProgressIndicator(
backgroundColor: Colors.white,
),
),
),
);
}
void _showerrorDialog(String message) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'An Error Occurs',
style: TextStyle(color: Colors.blue),
),
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: () => Navigator.of(context, rootNavigator: true).pop())
],
),
);
}
}
最佳答案
找到这个答案(不是我的):
不是问题的指示,它只是表明代码执行不是逐行执行的同步代码,而是从调用堆栈中某个位置开始的已完成 Future 的回调
关于flutter - flutter 错误 : <asynchronous suspension>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68301218/
一 点睛 当线程在访问某个对象时,发现条件不满足,就暂时挂起等待条件满足时再次访问,这就是 Guarded Suspension 设计模式。该设计模式的关注点在于临界值的条件是否满足,当达到设置的临界
我正在尝试使用 Suspense 在 Promise 未解决时呈现后备。我做错了什么? 它应该在 fetch promise 不返回数据时呈现回退。但是当我尝试从浏览器获取数据时,回退不会出现。 ex
我想延迟加载我的组件以减少我的初始包大小并使用 react 路由器使用代码拆分即时获取组件。 但是,当使用 React Suspense 时,它们会强制您使用后备进行加载。 这行不通: const
我知道 React suspense 是新的,还没有正式发布生产,但我想知道它的主要好处是/或使用它会是什么? 我看不出它所做的任何事情都是“新的”或替换不存在的东西? 我知道它允许我从上到下加载东西
据我所知,Suspense 组件是 code splitting 的 React-ian 方法。 ,这使得网页加载速度更快。现在,假设您有一个如下所示的组件层次结构: }>
我想在产品添加成功后显示一个对话框,但是当我点击“添加到购物车”按钮时,我收到了图像中的那种类型的错误。 这个对话框想显示使用httpException,在我使用这个httpExcetion的prod
我有几个关于 React.Suspense 的问题。 下面是一些示例代码供引用: // components/ComponentA/index.js import React from "react"
我正在尝试使用 webpack 构建一个基本的 react 惰性应用程序。它成功创建了 block ,但是当应用程序运行时,它在错误的目录中查找 block ,因此,应用程序崩溃。我的构建目录是 di
我有点卡在如何实现这个问题上。 我正在渲染 map ,我需要 useRef 在创建 map 时将元素传递给 map 。 首先要做的是需要下载源文件,然后 mapkit 类就可以使用了。我用悬念来解决这
我正在使用一些非常标准的 create-react-app 样板,它使用延迟加载和 react-i18next 作为翻译库。该库使用 i18next-http-backend 从远程 API 获取翻译
我有一个使用 MUI 的 React 应用程序,现在我已经使用微调器实现了悬念,它在加载内容时作为后备组件启动。我很想为回退组件添加淡入/淡出过渡,因为目前这种变化太突然了。 我的设置(对于这个特定问
我没有找到任何明确的信息,所以我决定向你询问。我有基于 redux 基础设施的应用程序。有没有办法使用 Suspense 来等待 axios 的 redux 获取数据?我将我的操作调用放在 compo
我目前正在使用 React 16 与 Suspense 和 Lazy 来对我的代码库进行代码分割。虽然我想预加载组件。 在下面的示例中,我有两条路线。有没有办法在 Prime 安装后立即预加载 Dem
我正在努力寻找使用 的问题悬疑和 react 钩子(Hook) . 有几个关键问题使用下面的 React 代码。 import { Suspense, useState, useEffect } fr
通常当我返回一个依赖于获取数据的组件(我使用的是 nextjs 13)时,我有条件地渲染元素以确保值可用: 表格组件: export const Table = ({ ...props }) => {
通常当我返回一个依赖于获取数据的组件(我使用的是 nextjs 13)时,我有条件地渲染元素以确保值可用: 表格组件: export const Table = ({ ...props }) => {
给定一个具有数千个连接设备的 Azure IOT 中心。鉴于设备的某些子集存在某种软件和硬件问题,导致 IOT 中心充斥着(不良)流量。 我们如何“暂停”或以其他方式标记特定设备,而不从设备注册表中删
我正在尝试写一个 Jest使用 React.Suspense 的组件的单元测试. 正在测试的组件模块的简化版本: MyComponent.js import React from 'react'; e
Gor Nishanov、Jens Maurer、Richard Smith 和 Daveed Vandevoorde 的“协程措辞”(文档 C++ P0057R5),参见 P0057r5 , 讲了很
我正在研究 和 React.lazy()概念,我想更好地理解为了向现有应用程序添加一些逻辑会发生什么。 让我们从定义开始: The React.lazy function lets you rende
我是一名优秀的程序员,十分优秀!