conversation 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 53

Conversation #

Conversation Widget For Flutter.

Demo #

enter image description here

Getting Started #

Create GlobalKey for ConversationWidgetState in case you need to manipulate it's state

final GlobalKey<ConversationWidgetState> _key = GlobalKey<ConversationWidgetState>();

Obtain participants and their messages from oldest to newest

final _messages = List<Message>()
  ..addAll([
    Message(
      id: 1,
      sentAt: DateTime.now(),
      body: 'Test #1',
      from: 1,
    ),
    Message(
      id: 2,
      sentAt: DateTime.now(),
      body: 'Test #2',
      from: 2,
    ),
    Message(
      id: 3,
      sentAt: DateTime.now(),
      body: 'Test #3',
      from: 3,
    ),
  ]);

final _participants = [
  Participant(
    id: 1,
    name: 'רוני אלמוני',
    isMyself: true,
  ),
  Participant(
    id: 2,
    name: 'ישראל ישראלי',
  ),
  Participant(
    id: 3,
    name: 'Third Participant',
  ),
];

Finally, pass mentioned data along with messageViewedCallback and sendMessageCallback to ConversationWidget

/// ...
ConversationWidget(  
  key: _key,  
  messages: _messages,
  messageViewedCallback: (message, index) async {
    await Future.delayed(Duration(seconds: 3));
    setState(() {
      message.state = MessageState.VIEWED;
    });
  },
  participants: _participants,
  sendMessageCallback: (body) async {
    await Future.delayed(Duration(seconds: 3));
    return true;
  },
),

[0.0.3] - 2020-04-08 #

  • messageViewedCallback has been added
  • Message now has state property which is enum

[0.0.2] - 2020-04-08 #

  • Input has been added
  • sendMessageCallback has been added

[0.0.1] - 2020-04-08 #

  • Initial release

example/lib/main.dart

import 'dart:math';

import 'package:conversation/conversation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lipsum/lipsum.dart';

void main() => runApp(AppRoot());

class AppRoot extends StatefulWidget {
  AppRoot({Key key}) : super(key: key);

  @override
  _AppRootState createState() => _AppRootState();
}

class _AppRootState extends State<AppRoot> {
  final GlobalKey<ConversationWidgetState> _key = GlobalKey<ConversationWidgetState>();

  final List<Message> _messages = List<Message>();

  final List<Participant> _participants = List<Participant>();

  @override
  void initState() {
    super.initState();

    _messages.addAll(_generateMessages(0));
    _participants.addAll(_generateParticipants());
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.arrow_downward),
              onPressed: () {
                _key.currentState.jumpToLast();
              },
            ),
            IconButton(
              icon: Icon(Icons.arrow_upward),
              onPressed: () {
                _key.currentState.jumpToFirst();
              },
            ),
            IconButton(
              icon: Icon(Icons.message),
              onPressed: () {
                final messages = _generateMessages(_messages.length);
                setState(() {
                  _messages.addAll(messages);
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.done),
              onPressed: () {
                setState(() {
                  _messages.last.state = MessageState.DELIVERED;
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.done_all),
              onPressed: () {
                setState(() {
                  _messages.last.state = MessageState.VIEWED;
                });
              },
            ),
          ],
          title: Text('Conversation'),
        ),
        body: ConversationWidget(
          key: _key,
          messages: _messages,
          messageViewedCallback: (message, index) async {
            await Future.delayed(Duration(seconds: 2));
            setState(() {
              message.state = MessageState.VIEWED;
            });
          },
          participants: _participants,
          sendMessageCallback: (body) async {
            await Future.delayed(Duration(seconds: 3));
            return true;
          },
        ),
      ),
      locale: Locale('en'),
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('en'), // English
        const Locale('he'), // Hebrew
      ],
    );
  }

  Iterable<Message> _generateMessages(
    int from, {
    int length = 100000,
  }) {
    final random = Random();
    final now = DateTime.now();
    final initialSentAt = now.subtract(Duration(days: 300));

    return List.generate(length, (index) {
      return Message(
        id: from + index + 1,
        body: random.nextBool()
            ? createSentence()
            : 'הראשי לימודים ב שתי, ב ובמתן הבהרה המקובל מלא. זאת גם מרצועת הספרות, מה היא כלליים קלאסיים. אחר דת באגים ולחבר. כלל את ריקוד קולנוע העברית, נפלו פולנית קצרמרים דת לוח, ויש או אחרים בקרבת המדינה.',
        from: random.nextInt(3) + 1,
        sentAt: initialSentAt.add(Duration(hours: (from + index))),
        state: MessageState.values[random.nextInt(2)],
      );
    });
  }

  Iterable<Participant> _generateParticipants() {
    return [
      Participant(
        id: 1,
        name: 'רוני אלמוני',
        isMyself: true,
      ),
      Participant(
        id: 2,
        name: 'ישראל ישראלי',
      ),
      Participant(
        id: 3,
        name: 'Third Participant',
      ),
    ];
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  conversation: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:conversation/conversation.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
17
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • conversation that is a package requiring null.

Health suggestions

Fix lib/widgets/conversation_input_widget.dart. (-0.50 points)

Analysis of lib/widgets/conversation_input_widget.dart reported 1 hint:

line 35 col 19: 'hasFloatingPlaceholder' is deprecated and shouldn't be used. Use floatingLabelBehaviour instead. This feature was deprecated after v1.13.2..

Format lib/conversation.dart.

Run flutter format to format lib/conversation.dart.

Format lib/models/models.dart.

Run flutter format to format lib/models/models.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/widgets/conversation_widget.dart (Run flutter format to format lib/widgets/conversation_widget.dart.)
  • lib/widgets/message_body_widget.dart (Run flutter format to format lib/widgets/message_body_widget.dart.)
  • lib/widgets/message_widget.dart (Run flutter format to format lib/widgets/message_widget.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bubble ^1.1.9+1 1.1.9+1
flutter 0.0.0
intl ^0.16.0 0.16.1
meta ^1.1.8 1.1.8 1.2.2
scrollable_positioned_list ^0.1.3 0.1.6
Transitive dependencies
collection 1.14.12 1.14.13
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test