Provides Iterables That Implements The ChangeNotifier Class

notifiable_iterables Provides iterables that implements the ChangeNotifier class.

pub.dev: https://pub.dev/packages/notifiable_iterables

GitHub: https://github.com/Cynnexis/notifiable_iterables

API Documentation: https://cynnexis.github.io/notifiable_iterables/

:electric_plug: Getting Started

:hammer_and_pick: Installation

It is recommended to install this package via pub.

To install this package in your project, open the pubspec.yaml, see this section.

Running the Example

The example/ directory contains an Android Studio project that uses notifiable_iterables. To make it run, open the project using Android Studio to launch the configuration example.

Buttons describing the configuration

If you don't have Android Studio, please open a terminal in the example project directory, and execute the following lines:

# Get the dependencies
pub get

# Check that a device is connected to this computer
flutter devices

# Run the example
flutter run

:dart: Usage

The full documentation is available here.

To use this library, you need to import it in your dart file:

import 'package:notifiable_iterables/notifiable_iterables.dart';

Then, you can use the following classes:

  1. NotifiableList<E>: A notifiable list. It has the same functions as List<E>.
  2. NotifiableSet<E>: A notifiable set. It has the same functions as Set<E>.
  3. NotifiableMap<K, V>: A notifiable map. It has the same functions as Map<K, V>.

Those classes can be uses exactly like their iterable equivalent.

Example:

// Create a notifiable list
NotifiableList<int> list = NotifiableList<int>.of(<int>[0, 1, 2, 3]);
print(list[2].toString()); // prints "2"

// Add a listener
list.addListener(() => print("New list: $list"));

// Change the list
list[3] = 4; // Notify the listeners, the console will show the updated list

:building_construction: Build With

:handshake: Contributing

To contribute to this project, please read our CONTRIBUTING.md file.

We also have a code of conduct to help create a welcoming and friendly environment.

:writing_hand: Authors

Please see the CONTRIBUTORS.md file.

:page_facing_up: License

This project is under the BSD License. Please see the LICENSE.txt file for more detail (it's a really fascinating story written in there!)

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add notifiable_iterables

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  notifiable_iterables: ^1.1.1

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

Import it

Now in your Dart code, you can use:

import 'package:notifiable_iterables/notifiable_iterables.dart';

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:notifiable_iterables/notifiable_iterables.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final String appName = "Example for Notifiable Iterables";

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<NotifiableList<BigInt>>(
      create: (context) => NotifiableList<BigInt>(),
      child: MaterialApp(
        title: appName,
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: MyHomePage(title: appName),
      ),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage> {
  /// Variable holding the fibonacci stream
  late Stream<BigInt> fibonacciStream;

  /// Variable holding the subscription to the fibonacci stream. It can control the stream by pausing it or resuming it.
  late StreamSubscription<BigInt> fibonacciStreamSubscription;

  @override
  void initState() {
    super.initState();
    // Launch the fibonacci stream.
    fibonacciStream = fibonacci(interval: Duration(seconds: 1));
    fibonacciStreamSubscription =
        fibonacciStream.listen(onFibonacciNumberIsComputed);
  }

  /// Callback for the fibonacci stream.
  ///
  /// It add the newly computed fibonacci number to the [NotifiableList]. The list then notify the UI.
  void onFibonacciNumberIsComputed(BigInt fibonacciNumber) {
    Provider.of<NotifiableList<BigInt>>(context, listen: false)
        .add(fibonacciNumber);
  }

  @override
  void dispose() {
    super.dispose();
    // Stop the stream
    fibonacciStreamSubscription.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: <Widget>[
          // Button in the appbar to reset the fibonacci stream and list
          IconButton(
            icon: Icon(Icons.replay),
            onPressed: () => setState(() {
              fibonacciStreamSubscription.cancel();
              Provider.of<NotifiableList<BigInt>>(context, listen: false)
                  .clear();
              fibonacciStream = fibonacci(interval: Duration(seconds: 1));
              fibonacciStreamSubscription = fibonacciStream.listen((event) {
                Provider.of<NotifiableList<BigInt>>(context, listen: false)
                    .add(event);
              });
            }),
          ),
        ],
        // Loading bar to show whether the stream is activated or not
        bottom: PreferredSize(
          preferredSize: Size(double.infinity, 6.0),
          child: LinearProgressIndicator(
            backgroundColor: Colors.lightBlueAccent.withOpacity(0.3),
            valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlueAccent),
            value: fibonacciStreamSubscription.isPaused ? 0.0 : null,
          ),
        ),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("The fibonacci numbers are:"),
              Consumer<NotifiableList<BigInt>>(
                builder: (context, fibNumbers, _) => ListView.separated(
                  itemCount: fibNumbers.length,
                  separatorBuilder: (context, index) => Divider(height: 2),
                  // Disable scroll because its parent is a Column
                  physics: NeverScrollableScrollPhysics(),
                  // Shrink the list
                  shrinkWrap: true,
                  itemBuilder: (context, index) => ListTile(
                    leading: Container(
                      margin: EdgeInsets.all(10),
                      padding: EdgeInsets.all(10),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(200)),
                        color: Colors.grey.withAlpha(100),
                      ),
                      child: Text("#${index + 1}"),
                    ),
                    title: Text(fibNumbers[index].toString()),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      // Button to pause and resume the stream
      floatingActionButton: FloatingActionButton(
        child: Icon(fibonacciStreamSubscription.isPaused
            ? Icons.play_arrow
            : Icons.pause),
        tooltip: fibonacciStreamSubscription.isPaused
            ? "Resume the computation"
            : "Pause the computation",
        onPressed: () => setState(() => fibonacciStreamSubscription.isPaused
            ? fibonacciStreamSubscription.resume()
            : fibonacciStreamSubscription.pause()),
      ),
    );
  }
}

/// The fibonacci function.
///
/// This functions computes the first [n] fibonacci numbers. If [n] is not given, it will never stop. This function
/// yields every new results through a stream of [BigInt]. If [interval] is given, a delay will be respected between
/// two computation.
Stream<BigInt> fibonacci({int? n, Duration? interval}) async* {
  BigInt a = BigInt.from(0);
  BigInt b = BigInt.from(1);

  yield a;
  if (interval != null) await Future.delayed(interval);
  yield b;
  if (interval != null) await Future.delayed(interval);

  int counter = 0;
  while (n == null || counter < n) {
    BigInt c = BigInt.parse(a.toString());
    a = b;
    b = c + b;
    yield b;
    counter++;

    if (interval != null) await Future.delayed(interval);
  }
}

#flutter #dart #mobile-apps #mobile 

What is GEEK

Buddha Community

Provides Iterables That Implements The ChangeNotifier Class

Yashi Tyagi

1617449307

CA Classes - Best CA Classes Online

Chartered Accountancy course requires mental focus & discipline, coaching for CA Foundation, CA Inter and CA Finals are omnipresent, and some of the best faculty’s classes have moved online, in this blog, we are going to give the best way to find online videos lectures, various online websites provide the CA lectures, Smartnstudy one of the best site to CA preparation, here all faculty’s video lecture available.

check here : ca classes

#ca classes online #ca classes in delhi #ca classes app #ca pendrive classes #ca google drive classes #best ca classes online

Joseph  Murray

Joseph Murray

1624048020

How to Find All the Classes of a Package in Java

In this article let’s take a look at how to find all classes of a package in Java

To find all classes of a package in Java we can use the ClassHunter of Burningwave Core library. So we start by adding the following dependency to our pom.xml:

XML

1

<dependency>2
    <groupId>org.burningwave</groupId>3
    <artifactId>core</artifactId>4
    <version>8.4.0</version>5
</dependency>

The next steps are the following:

  • retrieving the ClassHunter through the ComponentContainer
  • defining a regular expression that we must pass to the **ClassCriteria **object that will be injected into the **SearchConfig **object
  • calling the **loadInCache **method that loads in the cache all loadable classes of the indicated paths, then applies the criteria filter and then returns the **SearchResult **object which contains the classes that match the criteria

#java #classes #class #packages #package #how to find all the classes of a package in java

Coy  Roberts

Coy Roberts

1600864380

Javascript ES6 Iterators: Complete Guide on Iterables and Iterators

Javascript iterators is a new concept of ES6 in which it processes each of the items in the collection, which is a pervasive operation. Iterators are a new way to _loop _over any collection in JavaScript.

They were introduced in ES6 and have become popular since they are widely JavaScript provides several ways of iterating over the collection, from simple for loops to map() and filter() Iterators and  Generators bring the concept of iteration directly into the core language and provide a mechanism for customizing the behavior of loops.

Iterators in Javascript

An iterator is a new concept of ES6. An Iterator is an object that lets us iterate through an Array, an Object, a String, or even custom Objects.

The Iterator allows us to effectively loop over a collection of objects like an arraystringobjects, or other data structures.

The most common Iterator in Javascript is the Array iterator, which returns each value in the associated array in sequence.

#javascript #javascript es6 #iterators #iterables

Alayna  Rippin

Alayna Rippin

1602907200

Iterable and Iterators In Dart

Introduction

In this article, we are going to talk about Itrables and how it uses the iterator to access the elements sequentially.

What is an iterable

It’s a **collection, **A collection of values, or “elements”, that can be accessed sequentially each element at a time.

_For Example, _List and Set classes are both Iterable, as are most classes in the dart:collection library.

Each element of the iterable is accessed by getting an Iterator using the iterator getter and using it to step through the values. Stepping with the iterator is done by calling Iterator.moveNext, and if the call returns true, the iterator has now moved to the next element, which is then available as Iterator.current. If the call returns false, there are no more elements.

We can also iterate over the elements of an Iterable using the for-in loop construct, which uses the iterator getter behind the scenes.

For example, you can iterate over all of the keys of a Map, because Map keys are iterable.

Image for post

Note:_ Although Map doesn’t implement Iterable, you can get Iterables from it using the Map _keys_ and _values_ properties._

Advantages of iterables

Besides being able to use them with a for-in loop, an iterable gives you access to lots of other features.

For example, Because of some methods available, such as mapwhereany, and takeWhile etc.

The _Iterable_ class provides two methods that you can use to verify conditions:

_any()_: Returns true if at least one element satisfies the condition.

_every()_: Returns true if all elements satisfy the condition.

#iterables #dart #collection #iterators #lists

What are Iterables and Iterators in Python

While writing an article about Generators, I realized that though iteration, iterable and iterator are so commonly used in programming; there is a certain degree of confusion around them. It’s crucial to understand the underlying concept for a better implementation. This is going to be a short and quick article to help us determine what is an iterable and what is an iterator.


Iteration

  • In layman’s language it is ‘repeating steps’.
  • Iteration in programming is a repetition of a block of code for a certain number of times.
  • This can be achieved by using loops.

Iterable

  • Iterable is an object which can be looped over or iterated over.
  • e.g. List, Tuple, Set, Dictionary, File.
  • In simpler words, iterable is a container which has data or values and we perform iteration over it to get elements one by one. (Can traverse through these values one by one)
  • Iterable has an in-built dunder method iter. A simpler way to determine whether an object is iterable is to check if it supports iter. How? Using dir( ), it returns the list of attributes and methods supported by an object.

Iterator

  • Iterator is an iterable object with a state so it remembers where it is during iteration.
  • e.g. Generator
  • Iterator performs the iteration to access the elements of the iterable one by one. As it maintains the internal state of elements, iterator knows how to get the next value.
  • Iterators can only move forward using _next _. It cannot go back or cannot be reset.
  • Iterator supports in-built dunder methods _iter _and next.

#iteration #python #data-science #programming #iterators