1
I’m using getx for state management and I’m having a mistake that says the following:
"Getlifecyclebase" not found. You need to call "Get.put(Getlifecyclebase())" or "Get.lazyPut(()=>Getlifecyclebase())"
Here’s the view:
import 'package:flutter/material.dart';
import 'package:flutter_application_stock/controllers/product_controller.dart';
import 'package:get/get.dart';
class HistoryScreen extends GetWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: GetX<ProductController>(
init: Get.put(ProductController()),
builder: (ProductController productController) {
if (productController != null) {
return Expanded(
child: ListView.builder(
itemCount: productController.produtos.length,
itemBuilder: (_, index) {
return Text(productController.produtos[index].nome);
},
),
);
} else {
return Text("Loading");
}
},
)));
}
}
The controller:
import 'package:flutter_application_stock/models/produto_model.dart';
import 'package:flutter_application_stock/services/database.dart';
import 'package:get/get.dart';
class ProductController extends GetxController {
Rx<List<ProductModel>> productList = Rx<List<ProductModel>>();
List<ProductModel> get produtos => productList.value;
@override
void onInit() {
productList.bindStream(Database().productStream());
}
}
A database:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter_application_stock/models/produto_model.dart';
class Database {
Firestore _firestore = Firestore.instance;
Stream<List<ProductModel>> productStream() {
return _firestore
.collection("products")
.snapshots()
.map((QuerySnapshot query) {
List<ProductModel> retVal = List();
query.documents.forEach((element) {
retVal.add(ProductModel.fromDocumentSnapshot(element));
});
return retVal;
});
}
}
the model:
import 'package:cloud_firestore/cloud_firestore.dart';
class ProductModel {
String id;
String nome;
String embalagem;
String categoria;
ProductModel({this.id, this.nome, this.embalagem, this.categoria});
ProductModel.fromDocumentSnapshot(DocumentSnapshot snapshot) {
id = snapshot.documentID;
nome = snapshot.data["nome"];
embalagem = snapshot.data["embalagem"];
categoria = snapshot.data["categoria"];
}
}
I’d appreciate any help