ksnotification 0.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 57

ksnotification #

1、借鉴iOS NotificationCenter实现消息广播,源码简洁明了只有80余行。

2、简单4步实现消息的监听、广播、接收、销毁。

3、除了简单易用还是简单易用

Use this package as a library

1. Depend on it

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

dependencies: ksnotification: last

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:

const String _kPriceChange = 'kPriceChange';

class _KSPackagesManagerPageState extends State<KSPackagesManagerPage> {
  String _price = '';

  @override
  void initState() {
    super.initState();
    /*1、添加监听*/
    KSNotificationCenter.shard()
        .addListener(_kPriceChange, _priceChangeCallback);
  }

  /*2、监听回调*/
  void _priceChangeCallback(dynamic price) {
    setState(() {
      _price = price;
    });
  }

  @override
  void dispose() {
    /*4、移除监听*/
    KSNotificationCenter.shard()
        .removeListener(_kPriceChange, _priceChangeCallback);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    String iphone_price = '3889元';
    return Scaffold(
      appBar: KSAppBar.ks_init(title: widget.pageTitle),
      body: ListView(
        children: <Widget>[
          KSListTile.ks_init(title: _price, onTap: null),
          KSListTile.ks_init(
              title: '价格修改为(${iphone_price})',
              onTap: () {
                /*3、发送消息*/
                KSNotificationCenter.shard().post(_kPriceChange, iphone_price);
              }),
        ],
      ),
    );
  }
}

0.1.6 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:ksnotification/ksnotification.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Ksnotification.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  ksnotification: ^0.1.6

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:ksnotification/ksnotification.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
57
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
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

12 out of 12 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test