The name 'File' is defined in the libraries 'dart:html' and 'dart:io'

1,696

Please check you need dart.html or not. If you need both packages, you can use a typecast operator as.

//import
import 'dart:io' as io;
import 'dart:html';


//Usage
io.File imageFile;
File htmlFile;
Share:
1,696
Tech Rocks
Author by

Tech Rocks

Updated on December 29, 2022

Comments

  • Tech Rocks
    Tech Rocks 10 months

    Does anybody know how to solve this error here's my code and the imports the error is in the "File" the error is as follows:

    The name 'File' is defined in the libraries 'dart:html' and 'dart:io'.

     @override
      State createState() => ChatScreenState(receiverId: receiverId, receiverAvatar: receiverAvatar);
    }
    
    
    
    
    class ChatScreenState extends State<ChatScreen>
    {
      final String receiverId;
      final String receiverAvatar;
    
      ChatScreenState({
        Key key,
        @required this.receiverId,
        @required this.receiverAvatar,
      });
    
      final TextEditingController textEditingController = TextEditingController();
      final ScrollController listScrollController = ScrollController();
      final FocusNode focusNode = FocusNode();
      bool isDisplaySticker;
      bool isLoading;
    
      File imageFile;
      String imageUrl;
    
      String chatId;
      SharedPreferences preferences;
      String id;
      var listMessage;
    
      @override
      void initState() {
        // TODO: implement initState
        super.initState();
        focusNode.addListener(onFocusChange);
    
        isDisplaySticker = false;
        isLoading = false;
    
        chatId = "";
    
        readLocal();
      }
    

    I also imported this

    import 'dart:async';
    import 'dart:html';
    import 'dart:io';
    import 'package:file/file.dart';
    import 'package:cached_network_image/cached_network_image.dart';
    import 'package:cloud_firestore/cloud_firestore.dart';
    import 'package:firebase_storage/firebase_storage.dart';
    import 'package:flutter/material.dart';
    import 'package:telegramchatapp/Widgets/FullImageWidget.dart';
    import 'package:telegramchatapp/Widgets/ProgressWidget.dart';
    import 'package:fluttertoast/fluttertoast.dart';
    import 'package:image_picker/image_picker.dart';
    import 'package:intl/intl.dart';
    import 'package:shared_preferences/shared_preferences.dart';
    

    imports Main sample of code

    • paulsm4
      paulsm4 over 2 years
      Q: Have you tried qualifying the variable type with the package name, e.g. io.File imageFile;?
    • Rebar
      Rebar over 2 years
      Use conditonal imports: medium.com/@dvargahali/…