im trying to use scoped model in 2 screens in the app and i dont want to run the app with scoped model, i just initialize scoped model in first screen and it worked but i got an error in the second screen where i navigate to it. so what do i do?
first i call the first screen from the pre screen like this
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ServiceDetails(model: new CartModel()),
)
);
then in ServiceDetails i didnt get any error so in build widget
@override
Widget build(BuildContext context) {
return ScopedModel(
model: widget.model,
child: Scaffold(...)
);
}
and i have a cart button which on tap:
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => new Cart()
),
);
},
Cart class:
class Cart extends StatefulWidget {
@override
_CartState createState() => _CartState();
}
class _CartState extends State<Cart> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Your Cart")),
body: ScopedModel.of<CartModel>(context, rebuildOnChange: true).cart.length == 0 ?
Container(
alignment: Alignment.center,
child: Text("Your cart is empty!",style: new TextStyle(color: Colors.grey))
) :
Container(
padding: EdgeInsets.only(top:15),
child: cartListView()
)
);
}
Widget cartListView(){
return ScopedModelDescendant<CartModel>(
builder: (context, child, model) {
return ListView.builder(
shrinkWrap: true,
itemCount: ScopedModel.of<CartModel>(context,rebuildOnChange: true).total,
itemBuilder: (context, index) {
return Container(
child: Image.asset(model.cart[index].fs.image)
)
}
)})}
}
so when i enter cart page i got an error
can't find the correct scoped model
anyone help plz