Q: How can I update the value of the parameter with the value that come from API response? I am trying to update the value of totalPricewith the value that comes from the response from API. I have created a currentTotal methods that contains setState(). Then passed snapshot.data.price.totalAmountvalue to currentTotal in order to update the value of totalPrice.But, it doesnt update the value. Can you help?
double totalPrice = 0;
 @override
 Widget build(BuildContext context) {

   currentTotal(double x) {
      setState(() {
        totalPrice += x;
      });
   }

   return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      body: Center(
        child: FutureBuilder<SearchResult>(
          future: serviceOne.postCall(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              if (snapshot.data != null) {
                  return new Material(
                      child: CustomScrollView(
                      slivers: <Widget>[
                          SliverList(
                            delegate: SliverChildListDelegate([
                              ListTile(
                                title: new Text(totalPrice.toString()),
                              )
                           ]),
                          ),

                       ]

                  )

               }
               currentTotal(snapshot.data.price.totalAmount);
              else if (snapshot.hasError) {
                return Text("error....${snapshot.error}");
        }


A: There are many things needs to be fixed in your build.
1 - Your widget is StatefulWidget, to use FutureBuilder inside StatefulWidget read this:
https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
Briefly, create Future future; instance field, then assign it inside the initState and use that future for FutureBuilder.
2 - your setState not inside a method, you have probably syntax error there. Create a void method and use setState inside it.
3 - You don't need to check twice like:
if (snapshot.hasData) {
              if (snapshot.data != null) {

One of them enough, after the condition check, call your method includes setState, then display it.
Edit:
Here an example template for your solution:
class Test extends StatefulWidget {
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  Future<int> future;
  int price = 0;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: FutureBuilder<int>(
          future: future,
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return Center(
                child: Text(price.toString()),
              );
            }
            return Center(child: CircularProgressIndicator());
          },
        ),
      ),
    );
  }

  Future<int> fetchPrice() async {
    final response =
        await http.get('https://jsonplaceholder.typicode.com/posts/1');
    final data = json.decode(response.body);
    setState(() {
      price = data['userId'];
    });
    return data['userId'];
  }
}

