我从用户的文件夹中获取文件列表。我传输到 ListView.builder 的文件的名称。这是工作,但我认为,这是糟糕的架构。
一个方法 _getFilesFromDir() 调用频率很高。
如何进行正确的列表生成,以免在不改变文件列表的情况下更新界面?
class CharacteristList extends StatefulWidget {
@override
_CharacteristListState createState() => new _CharacteristListState();
}
class _CharacteristListState extends State<CharacteristList> {
List<String> filesList = new List<String>();
List<String> filesL = new List<String>();
@override
void initState() {
super.initState();
filesList = [];
}
Future<List<String>> _getFilesFromDir() async{
filesL = await FilesInDirectory().getFilesFromDir();
setState(() {
filesList = filesL;
});
return filesList;
}
_getFilesCount(){
_getFilesFromDir();
int count = filesList.length;
return count;
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: …Run Code Online (Sandbox Code Playgroud) 我从 Firestore 获取文档,它可以工作:
this.sub = this.beluginService.getBeluginById(this.personId)
.subscribe((documentSnapshot: firebase.firestore.DocumentSnapshot) => {
console.log(documentSnapshot.data());
}
Run Code Online (Sandbox Code Playgroud)
我的服务:
getBeluginById(id: string) {
return this.afs.collection('belugin').doc(id).get();
}
Run Code Online (Sandbox Code Playgroud)
在 console.log 中我得到一个对象:
{ id: "ya1jibU2pZx1niGiuAmp"
qwCF: [0, 0, 2, 0, 0, 6, 2]
qwCO: [0, 0, 0, 0, 2, 0, 0]
qwIMP: [10, 0, 2, 2, 2, 4, 0]
qwME: [0, 4, 0, 4, 2, 0, 0]
qwPL: [0, 0, 0, 0, 0, 0, 0]
qwRI: [0, 2, 2, 2, 2, 0, 0]
qwSH: [0, 0, 0, 0, 0, 0, …Run Code Online (Sandbox Code Playgroud) 我有订单 orderList 列表。如果是Empty,则FloatingActionButton 是隐藏的。如果 orderList 有产品 - 将显示 FAB。我的代码:
bool statusFAB = false;
_getFABState(){
setState(() {
if(!orderList.isEmpty){
statusFAB = true;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: _getFAB(),
backgroundColor: _kAppBackgroundColor,
body: Builder(
builder: _buildBody,
),
);
Widget _getFAB() {
if(statusFAB){
return FloatingActionButton(
backgroundColor: Colors.deepOrange[800],
child: Icon(Icons.add_shopping_cart),
onPressed: null);
}
}
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为条件只起作用一次,但 orderList 的状态可以随时更改。
这是我的代码,我不明白,如何更改主题的文本颜色
void main() => runApp(new MaterialApp(
title: '??????????????',
home: new CharacteristList(),
theme: new ThemeData(
primaryColor: Colors.lightBlue,
accentColor: Colors.lightBlueAccent,
),
)
Run Code Online (Sandbox Code Playgroud)
我的对象列表,例如
List<Product> products = [product1, product2, product1, product2, product1, product1]
Run Code Online (Sandbox Code Playgroud)
如何从列表中获取带有编号的唯一对象列表?
import 'package:built_value/serializer.dart';
import 'package:built_value/built_value.dart';
part 'product.g.dart';
abstract class Product implements Built<Product, ProductBuilder>{
int get id;
String get title;
String get image;
double get price;
int get volume;
static Serializer<Product> get serializer => _$productSerializer;
Product._();
factory Product([updates(ProductBuilder b)]) = _$Product;
}
Run Code Online (Sandbox Code Playgroud)
我想用对象获取其他列表:
class OrderPosition {
int id;
String title;
int count; // number of unique elements from list 'products'
}
Run Code Online (Sandbox Code Playgroud)
例如:
List<OrderPosition> = [
OrderPosition(1, title1, 4),
OrderPosition(2, title2, 2) …Run Code Online (Sandbox Code Playgroud)