Value is not setting while running but sets after hot restart

flutter hot reload not working android studio
flutter hot restart not working
flutter hot reload not working vscode
docker run
docker run --restart=always
docker run command in container
docker set environment variables
docker expose port

I have the following situation: there is a FutureBuilder in my build method:

FutureBuilder<List>(
            future: NutritionDataManager().getDishes(),
            initialData: List(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                List<Dish> dishes = snapshot.data.map((dish) {
                  return Dish(dish.id, dish.icon, dish.name, dish.gram, dish.calories, dish.time);
                }).toList();
                countTotalCalories(dishes);
                return SliverList(
                  delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                      return NutritionListItemWidget(
                        dish: snapshot.data[index],
                      );
                    },
                    childCount: snapshot.data.length,
                  ),
                );
              } else {
                return Container();
              }
            },
          )

This future gets data from database and if data is fetched (snapshot.hasData), it calls a method, which calculates something on the base of this data:

countTotalCalories(List<Dish> dishes) {
    int calSum = 0;
    dishes.forEach((dish) => calSum += dish.calories);    
    _currentCalories = calSum;        
  }

And after this value (_currentCalories) is used in another Widget. But when I run my app I always get zero value in _currentCalories, but then when I press hot restart, everything is ok. so, what's the matter f this problem and how can I solve it? Thanks in advance!

UPD

Here's the whole code of my screen:

class NutritionScreen extends StatefulWidget {
  const NutritionScreen({Key key}) : super(key: key);

  @override
  _NutritionScreenState createState() => _NutritionScreenState();
}

class _NutritionScreenState extends State<NutritionScreen> {
  int _currentCalories = 0;

  @override
  Widget build(BuildContext context) {
    var date = "Aug 27";

    return Scaffold(
      backgroundColor: Color(AppColors.white),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Color(AppColors.brandViolet),
        onPressed: () => showModalBottomSheet(
          context: context,
          isScrollControlled: true,
          builder: (context) => BottomNutritionModal(),
        ),
        child: Icon(Icons.add),
      ),
      body: SafeArea(
        child: CustomScrollView(slivers: <Widget>[
          SliverAppBar(
            title: Padding(
              padding: const EdgeInsets.only(right: 50.0),
              child: Center(child: Text(date, style: TextStyle(color: Colors.black))),
            ),
            backgroundColor: Colors.white,
            floating: true,
            automaticallyImplyLeading: true,
            leading: IconButton(
              icon: Icon(Icons.close, color: Colors.black),
              onPressed: () => Navigator.pop(context, false),
            ),
            elevation: 0,
          ),
          SliverPersistentHeader(
            delegate: _SliverPersistentHeaderDelegate(
              child: PreferredSize(
                preferredSize: Size.fromHeight(MediaQuery.of(context).size.height * 0.4),
                child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
                  return Container(
                    color: Colors.white,
                    child: Column(
                      children: <Widget>[
                        RichText(
                          textAlign: TextAlign.center,
                          text: TextSpan(
                            style: TextStyle(color: Colors.black, fontSize: Dimensions.boldTextSize, fontWeight: FontWeight.bold),
                            children: <TextSpan>[
                              TextSpan(text: "You have consumed \n"),
                              TextSpan(text: "500 out of 1900 cal", style: TextStyle(color: Color(AppColors.brandViolet))),
                            ],
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 10.0),
                          child: AnimatedCircularChart(
                            size: Size(constraints.maxHeight / 1.3, constraints.maxHeight / 1.3),
                            initialChartData: <CircularStackEntry>[
                              CircularStackEntry(
                                <CircularSegmentEntry>[
                                  CircularSegmentEntry(33.33, Color(AppColors.brandViolet)),
                                  CircularSegmentEntry(66.67, Color(AppColors.layoutBackgroundColor)),
                                ],
                              ),
                            ],
                            chartType: CircularChartType.Radial,
                            edgeStyle: SegmentEdgeStyle.round,
                            percentageValues: true,
                            holeLabel: "$_currentCalories",
                            labelStyle: new TextStyle(
                              color: Colors.blueGrey[600],
                              fontWeight: FontWeight.bold,
                              fontSize: 35,
                            ),
                          ),
                        )
                      ],
                    ),
                  );
                }),
              ),
            ),
          ),
          FutureBuilder<List>(
            future: NutritionDataManager().getDishes(),
            initialData: List(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                List<Dish> dishes = snapshot.data.map((dish) {
                  return Dish(dish.id, dish.icon, dish.name, dish.gram, dish.calories, dish.time);
                }).toList();
                countTotalCalories(dishes);
                return SliverList(
                  delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                      return NutritionListItemWidget(
                        dish: snapshot.data[index],
                      );
                    },
                    childCount: snapshot.data.length,
                  ),
                );
              } else {
                return Container();
              }
            },
          )
        ]),
      ),
      // bottomNavigationBar: SafeArea(child: NutritionBottomInputWidget()),
    );
  }

  countTotalCalories(List<Dish> dishes) {
    int calSum = 0;
    dishes.forEach((dish) => calSum += dish.calories);
    setState(() {
      _currentCalories = calSum;
    });
  }
}

Use below code might help you. put _currentCalories inside setState method.

 countTotalCalories(List<Dish> dishes) {
  int calSum = 0;
  dishes.forEach((dish) => calSum += dish.calories);
  if (mounted){
    setState(() {
      _currentCalories = calSum;
    });
  }
}

Automating with STEP 7 in LAD and FBD: SIMATIC S7-300/400 , contents of the load memory are retained during a memory reset. The CPU sets the parameters for all modules, including its own, to their default values. reset also does not affect the diagnostic buffer, the realtime clock, or the run-time meters. Following this, the CPU enters the event “Reset to factory settings” in the  Set the SendAlert DWORD value to 0. Automatically restart. The option specifies that Windows automatically restarts your computer. By default, this option is turned on. To turn off this option, run the following command or modify the registry value: wmic recoveros set AutoReboot = False Set the AutoReboot DWORD value to 0.

did you try to put

_currentCalories = calSum;

in a setState ?

Popular Mechanics Complete Home How-to, HEATING TROUBLESHOOTING Heating system troubleshooting When Pump not working . Close inlet and return values , remove radiator , flush out , then refit or replace is necessary . Check therinostat or timer setting and reset if necessary . If pump seems to be running but outlet pipe is cool , check for uir lock by  When your chainsaw quits after it gets hot, you either have a problem with gas flow being restricted into the engine or with the spark. This is a common occurrence on older-model chainsaws. By replacing your spark plugs and keeping your gas lines clear you can reduce the chances of this problem recurring. Video of the Day

If you cant share AnimatedCircularChart, problem is could be like that

If you dont use your AnimatedCircularChart widget like this, tell me please and i ll update answer.

This is your usage,

AnimatedCircularChart(
  ...
  holeLabel: "$_currentCalories", // ***
  ...
)

I expect AnimatedCircularChart like this,

You need to override didUpdateWidget like that,

The Art of LEGO MINDSTORMS NXT-G Programming, Setting the slider in the middle makes the robot move straight—at least, the NXT will It's almost impossible to make your robot move perfectly straight, but you can get determines the duration you need to set to make your robot spin in a full circle. When you run a program, the values will reset to 0 at the start, will update  If the engine runs lean and roughly after hot starts for about a minute or two, then settles to normal, check your air temperature sensor readings. Often, this is caused by sensor heat soak, where the sensor absorbs more heat from the intake manifold than the air does. There are several approaches you can take to fixing this.

New York Produce Review, Failure from not running them right ends in a good deal of money lost. There are worthless machines, but there are also good ones. You can now see why it is best to start when eggs are cheap. Beside this the weather is warm and you will not have to take so much care of the Only practice will tell how high to set it. If the engine cannot dissipate that heat, it will likely stop running and will not restart. After the engine cools, you may be able to fire it up again, but it probably will bog down and stop

Hot reload, If you're working in an IDE/editor that supports Flutter's IDE tools, select Save Flutter web currently supports hot restart but not hot reload. When a code change introduces a compilation error, hot reload generates an This means that the first time you run a Flutter app and a static field is read, it is set to whatever value  That’s it – the setting has been implemented. It’s advisable, however, to restart your PC once after doing this to ensure that changes have taken effect. Windows Registry Editor. In case you’re running a version of Windows 8 that does not come with Local Group Policy Editor, the same can be done using the standard Registry Editor in

Planter and Sugar Manufacturer, When in this way one-fourth of the ferment tub is filled, yeast, by a direct conduct Time does not allow much to say here about this yeast any more than that "​starch-set yeasts" the uses of which here I cannot dwell upon, but which are just will start from 3 to 7 hours after complete setting and will vigorously run its course  It had many problems but starting hot or cold wasn't one of them, ran like a champ through all for seasons. About 4 years ago I stalled it in traffic and it wouldn't start, had the dead battery effect. Someone offered to jump start and it fired up. Then it shortly after, it began to not start after driving till warm.

Comments
  • Can you share another Widget, probably you are using statefulWidget right
  • @IbrahimKarahan, updated the question
  • Unchanged place inside AnimatedCircularChart right?, if yes can you share AnimatedCircularChart please
  • Still get the same exception
  • @Sergei Mikhailovskii I think data takes time to load into dishes list but countTotalCalories function call before data fetch. That's why you get zero value and when you press hot restart data is already fetched.
  • Use debugger to find data flow.
  • Yes, but in such case I get the following error: The following assertion was thrown building FutureBuilder<List<dynamic>>(dirty, state: _FutureBuilderState<List<dynamic>>#c3a6b): setState() or markNeedsBuild() called during build.
  • wrap it with an if clause that checks this.mounted
  • @MuratAslan, unfortunately didn't help