title: flutter - Image picker - need to convert 'List<XFile>' to 'List<File>?'
body: <p>I'm using image_picker package to get images and show them in a carousel.</p>
  <pre><code>    postNotifier(true).selectedPostImages != null
          ? Container(
              height: 400,
              width: 400,
              child: CarouselSlider.builder(
                  options: CarouselOptions(height: 300),
                  itemCount: selectedImagesList!.length,
                  itemBuilder: (BuildContext context, index, realIndex) {
                    final selectedImage = selectedImagesList[index];
                    return buildImage(selectedImage, index);
                  }),
            )
          : const SizedBox(
              height: 0,
            ),
  </code></pre>
  <p>and I'm getting the images for carousel builder from this buildImage() widget</p>
  <pre><code>  Widget buildImage(File selectedImage, int index) =&gt; Container(
          margin: EdgeInsets.symmetric(horizontal: 12),
          color: Colors.grey,
          child: Image.file(selectedImage),
        );
  </code></pre>
  <p>my PostNotifier class in another file</p>
  <pre><code>class PostNotifier extends ChangeNotifier {
  
    List&lt;File&gt;? _selectedPostImages;
    List&lt;File&gt;? get selectedPostImages =&gt; _selectedPostImages;
  
    Future&lt;List?&gt; pickPostImages() async {
      final _imageList = await ImagePicker().pickMultiImage(imageQuality: 5);
      if (_imageList != null) {
        _selectedPostImages = _imageList; //I'm getting the error here.
        notifyListeners();
      }
    }
  </code></pre>
  <p>The error flutter shows is:</p>
  <blockquote>
  <p>A value of type 'List' can't be assigned to a variable of type 'List?'.
  Try changing the type of the variable, or casting the right-hand type to 'List?'.</p>
  </blockquote>
  <p>I tried using flutter_absolute_path as suggested in other answers in such a situation to get the path and set it to the array but when I run on emulator I get this error</p>
  <pre><code>The plugin `flutter_absolute_path` uses a deprecated version of the Android embedding.
  To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
  If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.
  Launching lib\main.dart on Android SDK built for x86 in debug mode...
  lib\main.dart:1
  /C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_absolute_path-1.0.6/lib/flutter_absolute_path.dart:11:23: Error: Null safety features are disabled for this library.
  Try removing the package language version or setting the language version to 2.12 or higher.
    static Future&lt;String?&gt; getAbsolutePath(String uri) async {
                        ^
  Error: Cannot run with sound null safety, because the following dependencies
  don't support null safety:
  
   - package:flutter_absolute_path
  
  For solutions, see https://dart.dev/go/unsound-null-safety
  : Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
  lib/…/notifier/post.notifier.dart:101
          File tempFile = File(filePath);
                               ^
  /C:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_absolute_path-1.0.6/lib/flutter_absolute_path.dart:15:17: Error: Null safety features are disabled for this library.
  Try removing the package language version or setting the language version to 2.12 or higher.
      final String? path = await _channel.invokeMethod('getAbsolutePath', params);
                  ^
  2
  
  FAILURE: Build failed with an exception.
  
  * Where:
  Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102
  
  * What went wrong:
  Execution failed for task ':app:compileFlutterBuildDebug'.
  &gt; Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
  
  * Try:
  &gt; Run with --stacktrace option to get the stack trace.
  &gt; Run with --info or --debug option to get more log output.
  &gt; Run with --scan to get full insights.
  
  * Get more help at https://help.gradle.org
  
  BUILD FAILED in 1m 48s
  Exception: Gradle task assembleDebug failed with exit code 1
  Exited (sigterm)
  </code></pre>
  <p>and the app never opens on emualtor.</p>
  <p>What do I do? I want to implement this multi image picker.</p>