flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

The name 'Delta' is being referenced through the prefix 'quill', but it isn't defined in any of the libraries imported using that prefix. Try correcting the prefix or importing the library that defines 'Delta'.

Open foued-firas opened this issue 1 year ago • 1 comments

Is there an existing issue for this?

The question


import 'package:docs_clone/colors.dart';
import 'package:docs_clone/commun/widgets/loader.dart';
import 'package:docs_clone/models/document_model.dart';
import 'package:docs_clone/models/error_model.dart';
import 'package:docs_clone/repository/auth_repository.dart';
import 'package:docs_clone/repository/document_repository.dart';
import 'package:docs_clone/repository/socket_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' as quill;
import 'package:flutter_riverpod/flutter_riverpod.dart';




class DocumentScreen extends ConsumerStatefulWidget {
  final String id;
  const DocumentScreen({
    Key? key,
    required this.id,
  }) : super(key: key);

  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _DocumentScreenState();
}

class _DocumentScreenState extends ConsumerState<DocumentScreen> {
  TextEditingController titleController =TextEditingController(text: 'Untitled Document');
   quill.QuillController? _controller ;
  ErrorModel? errorModel;
  SocketRepository socketRepository =SocketRepository();
 @override
  void initState() {
   
    super.initState();
    socketRepository.joinRoom(widget.id);
    fetchDocumentData();
    socketRepository.changeListener((data){
    _controller?.compose(
  quill.Delta.fromJson(data['delta']), 
  _controller?.selection ?? const TextSelection.collapsed(offset: 0),
  quill.ChangeSource.remote,
);




    });
  }
  void fetchDocumentData()async{
     errorModel =
    await ref.read(documentRepositoryProvider).getDocumentById(ref.read(userProvider)!.token ,widget.id
    );
    if (errorModel!.data != null) {
      titleController.text = (errorModel!.data as DocumentModel).title;
    _controller = quill.QuillController(
        document: errorModel!.data.content.isEmpty
            ? quill.Document()
           
              :  quill.Document.fromJson(errorModel!.data.content),
              
        selection: const TextSelection.collapsed(offset: 0),
      );
      setState(() {});
    }
   _controller!.document.changes.listen((event) {
  if (event.source == quill.ChangeSource.local) {
    Map<String, dynamic> map = {
      'delta': event.source, // Use the 'delta' property
      'room': widget.id,
    };
    socketRepository.typing(map);
  }
});
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    titleController.dispose();
  }

  void updateTitle(WidgetRef ref , String title){
    ref.read(documentRepositoryProvider).updateTitle(
      token: ref.read(userProvider)!.token,
       id: widget.id,
        title: title );
  }
  @override
  Widget build(BuildContext context) {
    if(_controller==null){
      return Scaffold(
        body: Loader(),
      );
    }
    return Scaffold(
      appBar: AppBar(
        backgroundColor:kwhiteColor ,
        elevation: 0,
        actions: [
         Padding(
          
           padding: const EdgeInsets.all(10.0),
           child: ElevatedButton.icon(
            
            onPressed: (){},
            
            icon: const Icon(
              
              Icons.lock,
              size: 14,
            
            ),
             label: const Text('Share'),
             style: ElevatedButton.styleFrom(
              backgroundColor: kblueColor,
             ),
            ),
         )
        ],
        title: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(9.0),
            child: SingleChildScrollView(
              child: Row(
                
                children: [
                  Image.asset('assets/docs-logo.png',
                  height: 24 ,),
                  const SizedBox(height: 10,),
                  SizedBox(
                    width: 180,
                    child: SingleChildScrollView(
                      child: SingleChildScrollView(
                        child: TextField(
                     
                          controller: titleController,
                          decoration: const InputDecoration(
                            border: InputBorder.none,
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                color: kblueColor
                              )
                            ),
                            contentPadding: EdgeInsets.only(left: 10),
                            
                          ),
                          onSubmitted: (value)=>updateTitle(ref, value),
                          
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
        bottom: PreferredSize(preferredSize: const Size.fromHeight(1), 
        child: Container(
          decoration: BoxDecoration(
          border: Border.all(
            color: kGreyColor,
            width: 0.1
          ),
        ),))
      ),

      body: Center(
        child: Column(
          children: [
            const SizedBox(height: 10),
            quill.QuillEditor.basic(controller: _controller!),
            const SizedBox(height: 10),
            Expanded(
              child: SizedBox(
                width: 750,
                child: Card(
                  color: kwhiteColor,
                  elevation: 5,
                  child: Padding(
                    padding: const EdgeInsets.all(30.0),
                    child: quill.QuillEditor.basic(
                      controller: _controller!,
                     
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

foued-firas avatar Sep 29 '24 18:09 foued-firas

Can you share more details?

  • Do you use dart_quill_delta? How are you importing Delta?
  • Are you using any related packages to Quill or packages that depend on flutter_quill?
  • Can you try to remove the prefix quill in your imports?
  • What are you trying to do, or how did you encounter this issue?

EchoEllet avatar Sep 29 '24 19:09 EchoEllet

Due to the lack of details, I will close the issue. Feel free to open a new issue.

EchoEllet avatar Oct 17 '24 11:10 EchoEllet