title: Tried calling: openRead() in flutter
body: <p>I have a case that I don't understand, here I am trying to upload a document file to the server, I have been looking for some references, but when I open the file, I get an error  <strong>NoSuchMethodError: The method 'openRead' was called on null.</strong>
  <strong>Tried calling: openRead()</strong> .
  is there something wrong with my code ?</p>
  <p>this my code</p>
  <pre><code>import 'dart:io';
  
  import 'package:file_picker/file_picker.dart';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'package:async/async.dart';
  import 'package:path/path.dart';
  
  import '../../theme.dart';
  
  class Uploadcv extends StatefulWidget {
    @override
    _UploadcvState createState() =&gt; _UploadcvState();
  }
  
  class _UploadcvState extends State&lt;Uploadcv&gt; {
    File _file;
    String _namaFile;
    String _filePath;
  
    void _ambilfile() async {
      var path = await FilePicker.getFilePath(
          type: FileType.custom, allowedExtensions: [&quot;pdf&quot;, &quot;doc&quot;]);
      var file = await FilePicker.getFile(
          type: FileType.custom, allowedExtensions: [&quot;pdf&quot;, &quot;doc&quot;]);
  
      setState(() {
        _filePath = path.toString();
        _namaFile = path.toString().split(&quot;/&quot;).last;
        _file = file ?? '';
      });
  
      // print(_filePath);
      // print(_namaFile);
    }
  
    void _uploadFile(File file) async {
      // ignore: deprecated_member_use
      var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
      var length = await file.length();
      var uri = Uri.parse(&quot;myurl.com&quot;);
      var request = new http.MultipartRequest(&quot;POST&quot;, uri);
      var multipartFile = new http.MultipartFile('dokumen', stream, length,
          filename: basename(file.path));
      // add file to multipart
      request.files.add(multipartFile);
      var response = await request.send();
      if (response.statusCode == 200) {
        print('oke');
      } else {
        print('failed');
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          backgroundColor: Colors.white,
          appBar: AppBar(
            leading: IconButton(
              icon: Icon(
                Icons.arrow_back_ios,
              ),
              onPressed: () {
                Navigator.pop(context);
              },
            ),
            backgroundColor: Colors.indigoAccent,
            elevation: 0,
            centerTitle: true,
            title: Text(
              'Resume',
            ),
            actions: [
              IconButton(
                icon: Icon(Icons.file_upload),
                onPressed: () {
                  _ambilfile();
                },
              )
            ],
          ),
          body: Container(
            margin: EdgeInsets.symmetric(horizontal: defaultMargin),
            child: Center(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  _namaFile == null
                      ? Text(&quot;nama file ..&quot;)
                      : Text(&quot;nama file .. : $_namaFile&quot;),
                  SizedBox(
                    height: 15,
                  ),
                  _filePath == null
                      ? Text(&quot;nama file ..&quot;)
                      : Text(&quot;nama file .. : $_filePath&quot;),
                  OutlinedButton(
                    child: Text('upload'),
                    onPressed: () {
                      _uploadFile(_file);
                    },
                  )
                ],
              ),
            ),
          ));
    }
  }
  </code></pre>