when i run this code it shows an error that correct scopedmodel was not found. i think we have to declare another scoped model for bottomsheet,dialogs also did that using with same model but it behaving abnormally. how do i achive that how to use scoped models in such bottom sheets and dialogs.
i was noob at scoped model any help apreciated
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ResourcesModel extends Model{
String selectsubject = 'Select the subject';
List<String> sublist=[];
change(int index){
debugPrint('${sublist[index]}');
selectsubject=sublist[index];
notifyListeners();
}
fetchsubjects() {
Firestore.instance.collection("resources").document("17csea").get().then((DocumentSnapshot ds){
for (var item in ds['subjects']) {
sublist.add(item);
}
notifyListeners();
});
}
}
class Resources extends StatelessWidget {
final ResourcesModel resourcesModel =ResourcesModel();
void showbottomsheet(context) async{
double height =MediaQuery.of(context).size.height;
await showModalBottomSheet(
context: context,
builder: (context){
return Container(
height: height/2,
child: ScopedModelDescendant<ResourcesModel>(
builder:(context,_,model){
debugPrint('helelel');
return (model.sublist.isEmpty)?Center(child:CircularProgressIndicator()):
ListView.separated(
itemCount: model.sublist.length,
separatorBuilder: (context,_){
return Divider(
color: Theme.of(context).primaryColor,
);
},
itemBuilder: (context,index){
return ListTile(
title: Text(model.sublist[index]),
onTap: model.change(index),
);
},
);
}
),
);
}
);
}
@override
Widget build(BuildContext context) {
return ScpedModel<ResourcesModel>(
model:resourcesmodel,
chilld:ScopedModelDescendant<ResourcesModel>(
builder:(context,_,model){
return Container(
color: Color(0xFFF3F3F3),
child: RaisedButton(
child: Text(model.selectsubject),
onPressed: (){
if(resourcesModel.sublist.isEmpty){
resourcesModel.fetchsubjects();
}
},
),
);
}
),
);
}
}