Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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'. #2300

Open
1 task done
foued-firas opened this issue Sep 29, 2024 · 1 comment
Labels
question Further information is requested

Comments

@foued-firas
Copy link

foued-firas commented Sep 29, 2024

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 foued-firas added the question Further information is requested label Sep 29, 2024
@EchoEllet
Copy link
Collaborator

EchoEllet commented Sep 29, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants