You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I open the app. The app will call _callAPI() async {} since I put it in init. Then I click counter++ to add the value. Then it will show the added value in screen.then submit go to next page. when I click back page. The page will call the API then suddenly my scope model not working. when I try add value. The value not change.when I print in debug console. It did added the value.but It does not change in my screen. I think the problem is my scope model not working anymore in my app.
When I open the app. The app will call _callAPI() async {} since I put it in init. Then I click counter++ to add the value. Then it will show the added value in screen.then submit go to next page. when I click back page. The page will call the API then suddenly my scope model not working. when I try add value. The value not change.when I print in debug console. It did added the value.but It does not change in my screen. I think the problem is my scope model not working anymore in my app.
main.dart`class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
}
}
class _MyHomePageState extends State {
@OverRide
void initState(){
super.initState();
fetchList().then((value){
setState(() {
_callAPI();
});
});
}
_callAPI() async {
try{
String dataURL = "url";
http.Response response = await http.get(dataURL);
}
on Exception{
}
}
Widget build(BuildContext context) {
return ScopedModelDescendant(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
appBar: AppBar(
title: appBarTitle,
centerTitle: true,
actions: [
Stack(
children: [
new IconButton(icon: Icon(Icons.card_travel), onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => cartPage()),
);
}),
Container(
child: model.list.length != 0 ? new Positioned(
right: 11,
top: 11,
child: new Container(
padding: EdgeInsets.all(2),
decoration: new BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(6),
),
constraints: BoxConstraints(
minWidth: 16,
minHeight: 16,
),
child: Text(
"${model.list.length}",
style: TextStyle(
color: Colors.white,
fontSize: 12,
),
textAlign: TextAlign.center,
),
),
) : new Container()
),
],
),
],
backgroundColor: getMainColor(),
elevation: 10.0,
),
drawer: new Drawer(
child:
_drawerLeft(context),
),
body:
Container(
),
);}
);}
}`
scoped_models\main.dart
`List _list=[];
List get list{
return _list;
}
void addInList(Map newList){
_list.insert(0, newList);
notifyListeners();
}
`
The text was updated successfully, but these errors were encountered: