Using Riverpod to build a state but cant assign a list(array) to type int state, Dart Flutter

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fitness/fitness.dart';

class StepNotifier extends StateNotifier<int?> {
  StepNotifier() : super(0);
  void _readSteps() async {
    final now = DateTime.now();
    final steps = await Fitness.read(
      timeRange: TimeRange(start: now.subtract(const Duration(days: 1)), end: now),
      bucketByTime: 1,
      timeUnit: TimeUnit.days,
    );
    
    state = steps;  //Here is a error as cannot assign list(array) to type int ?
    
  }
}

final stepProvider = StateNotifierProvider((ref) => StepNotifier());

Basically Here I am writing a State to show steps taken to user with riverpod and using StateNotifierProvider but i cant assign steps to state variable as steps is a list which is a array in another progrramming language and the initial value of state is integer which is shown on Super(0)

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.