flutter - double http request when moving another page
I encountered a problem when I picked up the http request List which continued to increase when I went to the tab page and returned to its original page (see picture for result).

then, after leaving another page and returning to the original

how to optimize this?
see my code below:
class HomeTabDetail extends StatefulWidget
final Fixture fixture;
final FixtureModel model;
HomeTabDetail(this.fixture, this.model);
@override
_HomeTabDetailState createState() => _HomeTabDetailState();
class _HomeTabDetailState extends State<HomeTabDetail>
with SingleTickerProviderStateMixin
TabController controller;
// BannerAd bannerAd;
@override
void initState()
super.initState();
loadData();
print('initstate called');
controller = TabController(vsync: this, length: 4);
// FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
// bannerAd = buildBanner()..load();
@override
void dispose()
// bannerAd?.dispose();
controller.dispose();
print('dispose called');
super.dispose();
static final targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>, // Android emulators are considered test devices
);
BannerAd buildBanner()
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event)
print("bannerAd event is $event");
);
Future loadData() async
await Future.wait([
widget.model.fetchVenue(widget.fixture.venueId.toString()),
widget.model.fetchCountry(widget.fixture.league.countryId.toString()),
widget.model.fetchStandingTeams(widget.fixture.season.id.toString())
]);
@override
Widget build(BuildContext context)
// bannerAd.show();
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Info Pertandingan'),
bottom: TabBar(
controller: controller,
tabs: <Widget>[
Tab(text: 'RINCIAN'),
Tab(text: 'MEDIA'),
Tab(text: 'LINEUP'),
Tab(text: 'KLASEMEN'),
],
),
),
body: ScopedModelDescendant<FixtureModel>(
builder: (context, child, model)
return TabBarView(
controller: controller,
children: <Widget>[
DetailMatchTab(widget.fixture),
MediaMatchTab(),
LineupMatchTab(),
KlasemenMatchTab()
],
);
));
here fetchStandingTeams() method
Future<List<StandingTeams>> fetchStandingTeams(String seasonId) async
var response =
await http.get(Constant.standingById + seasonId + Constant.apiToken);
var responseBody = json.decode(response.body)['data'];
for (var standingJson in responseBody)
print(standingJson);
for (var data in standingJson['standings']['data'])
var standings = StandingTeams.fromJson(data);
print(standings);
addToStandingList(standings);
_isLoadingVenue = false;
notifyListeners();
return _standingTeams;
json api http dart
add a comment |
I encountered a problem when I picked up the http request List which continued to increase when I went to the tab page and returned to its original page (see picture for result).

then, after leaving another page and returning to the original

how to optimize this?
see my code below:
class HomeTabDetail extends StatefulWidget
final Fixture fixture;
final FixtureModel model;
HomeTabDetail(this.fixture, this.model);
@override
_HomeTabDetailState createState() => _HomeTabDetailState();
class _HomeTabDetailState extends State<HomeTabDetail>
with SingleTickerProviderStateMixin
TabController controller;
// BannerAd bannerAd;
@override
void initState()
super.initState();
loadData();
print('initstate called');
controller = TabController(vsync: this, length: 4);
// FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
// bannerAd = buildBanner()..load();
@override
void dispose()
// bannerAd?.dispose();
controller.dispose();
print('dispose called');
super.dispose();
static final targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>, // Android emulators are considered test devices
);
BannerAd buildBanner()
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event)
print("bannerAd event is $event");
);
Future loadData() async
await Future.wait([
widget.model.fetchVenue(widget.fixture.venueId.toString()),
widget.model.fetchCountry(widget.fixture.league.countryId.toString()),
widget.model.fetchStandingTeams(widget.fixture.season.id.toString())
]);
@override
Widget build(BuildContext context)
// bannerAd.show();
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Info Pertandingan'),
bottom: TabBar(
controller: controller,
tabs: <Widget>[
Tab(text: 'RINCIAN'),
Tab(text: 'MEDIA'),
Tab(text: 'LINEUP'),
Tab(text: 'KLASEMEN'),
],
),
),
body: ScopedModelDescendant<FixtureModel>(
builder: (context, child, model)
return TabBarView(
controller: controller,
children: <Widget>[
DetailMatchTab(widget.fixture),
MediaMatchTab(),
LineupMatchTab(),
KlasemenMatchTab()
],
);
));
here fetchStandingTeams() method
Future<List<StandingTeams>> fetchStandingTeams(String seasonId) async
var response =
await http.get(Constant.standingById + seasonId + Constant.apiToken);
var responseBody = json.decode(response.body)['data'];
for (var standingJson in responseBody)
print(standingJson);
for (var data in standingJson['standings']['data'])
var standings = StandingTeams.fromJson(data);
print(standings);
addToStandingList(standings);
_isLoadingVenue = false;
notifyListeners();
return _standingTeams;
json api http dart
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
1
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28
add a comment |
I encountered a problem when I picked up the http request List which continued to increase when I went to the tab page and returned to its original page (see picture for result).

then, after leaving another page and returning to the original

how to optimize this?
see my code below:
class HomeTabDetail extends StatefulWidget
final Fixture fixture;
final FixtureModel model;
HomeTabDetail(this.fixture, this.model);
@override
_HomeTabDetailState createState() => _HomeTabDetailState();
class _HomeTabDetailState extends State<HomeTabDetail>
with SingleTickerProviderStateMixin
TabController controller;
// BannerAd bannerAd;
@override
void initState()
super.initState();
loadData();
print('initstate called');
controller = TabController(vsync: this, length: 4);
// FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
// bannerAd = buildBanner()..load();
@override
void dispose()
// bannerAd?.dispose();
controller.dispose();
print('dispose called');
super.dispose();
static final targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>, // Android emulators are considered test devices
);
BannerAd buildBanner()
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event)
print("bannerAd event is $event");
);
Future loadData() async
await Future.wait([
widget.model.fetchVenue(widget.fixture.venueId.toString()),
widget.model.fetchCountry(widget.fixture.league.countryId.toString()),
widget.model.fetchStandingTeams(widget.fixture.season.id.toString())
]);
@override
Widget build(BuildContext context)
// bannerAd.show();
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Info Pertandingan'),
bottom: TabBar(
controller: controller,
tabs: <Widget>[
Tab(text: 'RINCIAN'),
Tab(text: 'MEDIA'),
Tab(text: 'LINEUP'),
Tab(text: 'KLASEMEN'),
],
),
),
body: ScopedModelDescendant<FixtureModel>(
builder: (context, child, model)
return TabBarView(
controller: controller,
children: <Widget>[
DetailMatchTab(widget.fixture),
MediaMatchTab(),
LineupMatchTab(),
KlasemenMatchTab()
],
);
));
here fetchStandingTeams() method
Future<List<StandingTeams>> fetchStandingTeams(String seasonId) async
var response =
await http.get(Constant.standingById + seasonId + Constant.apiToken);
var responseBody = json.decode(response.body)['data'];
for (var standingJson in responseBody)
print(standingJson);
for (var data in standingJson['standings']['data'])
var standings = StandingTeams.fromJson(data);
print(standings);
addToStandingList(standings);
_isLoadingVenue = false;
notifyListeners();
return _standingTeams;
json api http dart
I encountered a problem when I picked up the http request List which continued to increase when I went to the tab page and returned to its original page (see picture for result).

then, after leaving another page and returning to the original

how to optimize this?
see my code below:
class HomeTabDetail extends StatefulWidget
final Fixture fixture;
final FixtureModel model;
HomeTabDetail(this.fixture, this.model);
@override
_HomeTabDetailState createState() => _HomeTabDetailState();
class _HomeTabDetailState extends State<HomeTabDetail>
with SingleTickerProviderStateMixin
TabController controller;
// BannerAd bannerAd;
@override
void initState()
super.initState();
loadData();
print('initstate called');
controller = TabController(vsync: this, length: 4);
// FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
// bannerAd = buildBanner()..load();
@override
void dispose()
// bannerAd?.dispose();
controller.dispose();
print('dispose called');
super.dispose();
static final targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>, // Android emulators are considered test devices
);
BannerAd buildBanner()
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event)
print("bannerAd event is $event");
);
Future loadData() async
await Future.wait([
widget.model.fetchVenue(widget.fixture.venueId.toString()),
widget.model.fetchCountry(widget.fixture.league.countryId.toString()),
widget.model.fetchStandingTeams(widget.fixture.season.id.toString())
]);
@override
Widget build(BuildContext context)
// bannerAd.show();
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Info Pertandingan'),
bottom: TabBar(
controller: controller,
tabs: <Widget>[
Tab(text: 'RINCIAN'),
Tab(text: 'MEDIA'),
Tab(text: 'LINEUP'),
Tab(text: 'KLASEMEN'),
],
),
),
body: ScopedModelDescendant<FixtureModel>(
builder: (context, child, model)
return TabBarView(
controller: controller,
children: <Widget>[
DetailMatchTab(widget.fixture),
MediaMatchTab(),
LineupMatchTab(),
KlasemenMatchTab()
],
);
));
here fetchStandingTeams() method
Future<List<StandingTeams>> fetchStandingTeams(String seasonId) async
var response =
await http.get(Constant.standingById + seasonId + Constant.apiToken);
var responseBody = json.decode(response.body)['data'];
for (var standingJson in responseBody)
print(standingJson);
for (var data in standingJson['standings']['data'])
var standings = StandingTeams.fromJson(data);
print(standings);
addToStandingList(standings);
_isLoadingVenue = false;
notifyListeners();
return _standingTeams;
json api http dart
json api http dart
asked Nov 14 '18 at 4:23
Muhammad ImanudinMuhammad Imanudin
8312
8312
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
1
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28
add a comment |
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
1
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
1
1
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293164%2fflutter-double-http-request-when-moving-another-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293164%2fflutter-double-http-request-when-moving-another-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
take a look at this; medium.com/@diegoveloper/…
– diegoveloper
Nov 14 '18 at 4:59
1
It seems like you re-add the standings to the list every time initState is called, but never re-initialize the list of standings. Maybe just add a line that declares the list as empty before you repopulate it with the info you retreived?
– Kris
Nov 14 '18 at 6:06
@diegoveloper yes, I added that before. see pastebin.com/5wENUb1j for each tab. but for the code above as a controller of all tabs
– Muhammad Imanudin
Nov 14 '18 at 6:18
Uh oh, so true.. thank you @Kris
– Muhammad Imanudin
Nov 14 '18 at 6:28