4

I am building an app which uses an api and I am using the future builder to fetch the data but the problem is when the state changes it rebuilds and I want to prevent this from happen.

Thanks,

Bug
  • 243
  • 3
  • 15

1 Answers1

11

try using this :

class Example extends StatefulWidget {
  @override
 _ExampleState createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
 Future<response> future;

 @override
 void initState() {
   future = _asyncmethodCall();
   super.initState();
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
  future: future,
  builder: (context, snapshot) {
    // create some layout here
  },
 );
 }

Future<someResponse> _asyncmethodCall() async {
 // async code here
 }
}

similar question: How to deal with unwanted widget build?

GJJ2019
  • 4,624
  • 3
  • 12
  • 22