shenghy / flutter_shop Goto Github PK
View Code? Open in Web Editor NEW一个Flutter的电商实战项目,包括首页、列表页、详细页、购物车页和会员中心,配有全套文字和视频教程。
一个Flutter的电商实战项目,包括首页、列表页、详细页、购物车页和会员中心,配有全套文字和视频教程。
Error output from Xcode build:
↳
** BUILD FAILED **
lib/routers/routes.dart:3:1: Error: 'Router' is imported from both 'package:flutter/src/widgets/router.dart' and 'package:fluro/src/router.dart'.
上拉加载到底之后改变noMoreText之后 发送provide会导致左侧的provide监听执行 然后会拉去大分类下所有数据的第一页,但是这个时候你又把noMoreText设置为 没有更多了 就会导致只显示一页
//改变noMoreText数据
changeNoMore(String text){
noMoreText=text;
notifyListeners();
}
去掉这个 notifyListeners(); (会造成第一次加载完没有提示 第二次才会提示)
或者再写一个provide监听nomoretext的改变
Android resource linking failed
Output: D:\Android\asFlutterwork\flutter_shop-master\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:86: error: resource android:attr/fontVariationSettings not found.
D:\Android\asFlutterwork\flutter_shop-master\build\app\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:87: error: resource android:attr/ttcIndex not found.
error: failed linking references.
Compiler message:
file:///users/xxx/flutter/.pub-cache/hosted/pub.flutter-io.cn/flustars-0.2.5/lib/src/widget_util.dart:88:8: Error: No named parameter with the name 'onError'.
}, onError: (dynamic exception, StackTrace stackTrace) {
^^^^^^^
file:///users/xxx/flutter/.pub-cache/hosted/pub.flutter-io.cn/flustars-0.2.5/lib/src/widget_util.dart:115:8: Error: No named parameter with the name 'onError'.
}, onError: (dynamic exception, StackTrace stackTrace) {
^^^^^^^
file:///users/xxx/flutter/.pub-cache/hosted/pub.flutter-io.cn/cached_network_image-0.7.0/lib/src/cached_network_image_provider.dart:46:31: Error: The argument type 'Null Function(StringBuffer)' can't be assigned to the parameter type 'Iterable Function()'.
Another exception was thrown: HandshakeException: Handshake error in client (OS Error:
应该是 图片地址问题,
hotfix-2020-10
1.17.5
, 这个版本比较新. 适合初学.
1.22.0
之后的版本, 在 iOS+xcode 下, 会遇到各种奇怪编译报错. 不建议初学使用.1.17.5
版本.flutter run
技术胖 flutter 的接口怎么回事,现在重写,接口全挂了?给个回复吧,花了199买的课程,还不到一年,相应的服务就不行了,这样不行啊。胖子。有空的时候回复一下吧。
网上查了资料,发现有人说现在请求头不能写某几个key?
然后看了Dio库里的Headers类,发现里面有默认支持的几个key
httpHeaders = {
Headers.acceptHeader: "application/json, text/plain, /",
Headers.contentEncodingHeader: "gzip, deflate, br, drop",
Headers.contentLengthHeader: '',
Headers.contentTypeHeader: 'application/json'
}
是不是除了这几个,其他的都不支持呢(比如'origin')
跪求解惑,拜托大家了
改为
var temp=cartString==null?[]:json.decode(cartString.toString());
//把获得值转变成List
List<Map> tempList= (temp as List).cast();
// 如果数据不为空,那么需要给 cartInfoList 添加数据
if (tempList != null && tempList.length > 0) {
tempList.forEach((item) {
cartList.add(new CartInfoModel.fromJson(item));
});
}
//声明变量,用于判断购物车中是否已经存在此商品ID
var isHave= false; //默认为没有
int ival=0; //用于进行循环的索引使用
tempList.forEach((item){//进行循环,找出是否已经存在该商品
//如果存在,数量进行+1操作
if(item['goodsId']==goodsId){
tempList[ival]['count']=item['count']+1;
//关键代码-----------------start
cartList[ival].count++;
//关键代码-----------------end
isHave=true;
}
ival++;
});
我的项目的代码
import 'package:flutter/material.dart';
import 'package:flutter_shop_mall/model/cartInfoModel.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
class CartProvide extends ChangeNotifier {
String cartGoodsStr = "[]";
List<CartInfoModel> cartInfoList = [];
void save(String goodsId, String goodsName, int count, double presentPrice,
String images) async {
// 初始化SharedPreferences
SharedPreferences prefs = await SharedPreferences.getInstance();
// 获取数据
cartGoodsStr = prefs.getString('cartInfo');
debugPrint('cartGoodsStr 值 $cartGoodsStr');
// 判断cartString是否为空,为空说明是第一次添加,或者被key被清除了。
// 如果有值进行decode操作
var temp = cartGoodsStr == null ? [] : json.decode(cartGoodsStr.toString());
List<Map> tampList = (temp as List).cast();
// 如果数据不为空,那么需要给 cartInfoList 添加数据
if (tampList != null && tampList.length > 0) {
tampList.forEach((item) {
cartInfoList.add(new CartInfoModel.fromJson(item));
});
}
// 判断是否存在当前商品
bool isHaveThisGoods = false;
// 用于进行循环的索引使用
int ival = 0;
// 进行循环,找出是否已经存在该商品
tampList.forEach((item) {
debugPrint('ival 前 $ival');
// 如果存在,数量进行+1操作
if (item['goodsId'] == goodsId) {
debugPrint('有一样的数据,+1');
tampList[ival]['count'] = item['count'] + 1;
cartInfoList[ival].count++;
isHaveThisGoods = true;
}
ival++;
});
debugPrint('ival 后 $ival');
// 如果没有,进行增加
if (!isHaveThisGoods) {
Map<String, dynamic> newGoods = {
'goodsId': goodsId,
'goodsName': goodsName,
'count': count,
'price': presentPrice,
'images': images
};
tampList.add(newGoods);
cartInfoList.add(CartInfoModel.fromJson(newGoods));
}
//把字符串进行encode操作,
cartGoodsStr = json.encode(tampList).toString();
debugPrint('持久化数据 字符串 $cartGoodsStr');
debugPrint('持久化数据 列表 $cartInfoList');
prefs.setString('cartInfo', cartGoodsStr); //进行持久化
}
void remove() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
//prefs.clear();//清空键值对
prefs.remove('cartInfo');
// 置空数据
cartInfoList = [];
debugPrint('清空完成-----------------');
notifyListeners();
}
// 得到购物车中的商品
getCartInfoGoods() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var cartInfoStr = prefs.getString('cartInfo');
//把cartList进行初始化,防止数据混乱
cartInfoList = [];
// 判断得到的字符串是否有值,如果不判断会报错
if (cartInfoStr == null) {
cartInfoList = [];
} else {
var cartInfoJson = json.decode(cartInfoStr.toString());
List<Map> tampList = (cartInfoJson as List).cast();
tampList.forEach((item) {
cartInfoList.add(new CartInfoModel.fromJson(item));
});
}
notifyListeners();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.