livestream 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

LiveStream - Dart #

Pub Github Followers GitHub stars GitHub forks GitHub watchers Twitter Follow

LiveStream is a data holder class which can observe change of data in real-time and emit values too. Here's emitter subscriber pattern. It's developed in pure Dart.

⚡️ Getting Started #

Add Dependency #

Add below dependency in pubspec.yaml.

dependencies:
  livestream: ^1.0.2

Initialize LiveStream Instance #

You can create instance as below.

  LiveStream liveStream = new LiveStream();

Subscribe to Stream / Add Observer #

LiveStream event will be dispatched when data is changed. See below code to add observer / subscriber.

    liveStream.on("chat-message", (message) {
      print("Message Received: $message");
    });

Whenever data is emitted to chat-message channel/stream above block will be executed.

Emitting Events or Broadcasting #

The main idea behind LiveStream is that you can send and receive any events you want, with any data you want. Any objects that can be encoded as JSON will do, and binary data is supported too. See code below.

  void send() {
      String message = "Hi there!";
      liveStream.emit("chat-message", message);
  }

🚀 Sample Usage #

Sample code is available in /example directory.

🤝 Contribute #

If you want to contribute to this library, you're always welcome! See Contributing Guidelines.

✉️ Contact #

If you need any help, you can connect with me.

Visit:- shreyaspatil.dev

📃 License #

MIT License

Copyright (c) 2020 Shreyas Patil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[0.0.1] - 2020/02/20 #

  • This is test release of LiveStream package.

[1.0.0] - 2020/02/20 #

  • This is first release of LiveStream package.

[1.0.1] - 2020/02/21 #

  • Fixed code in LiveStream package.

[1.0.2] - 2020/02/21 #

  • Removed unnecessary code from package.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:livestream/livestream.dart';
import 'background.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'LiveStream Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'LiveStream Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String dateTime = DateTime.now().toString();
  Color textColor = Colors.blue;
  bool _isExecuting = false;
  BackgroundExecute backgroundExecute = new BackgroundExecute();
  LiveStream _liveStream = new LiveStream();

  void _startExecute() {
    if (!_isExecuting) {
      backgroundExecute.execDateTime();
      _isExecuting = true;
    }
    backgroundExecute.execColor();
  }

  void _initLiveStream() {
    _liveStream.on("dateTime", (value) {
      setState(() {
        dateTime = value.toString();
      });
    });

    _liveStream.on("text_color", (value) {
      setState(() {
        textColor = value;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Current Date & Time :',
            ),
            Text(
              '$dateTime',
              style: TextStyle(
                  color: textColor, fontWeight: FontWeight.bold, fontSize: 40),
            ),
            RaisedButton(
              onPressed: _initLiveStream,
              child: Text("Init Live Stream"),
            ),
            RaisedButton(
              onPressed: _startExecute,
              child: Text("Change Color"),
            )
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  livestream: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:livestream/livestream.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0