one_time_dialog 0.1.1

one_time_dialog #

A flutter package for showing a dialog X amount of times to the user. This package uses SharedPreferences to make sure dialogs aren't shown too many times.

The package can be used for showing some information to the user the first time they open the page. It can also be used with offset to show the user a dialog once in a while (like every fifth or tenth timewhen the user opens the page).

Usage #

To use this plugin, add one_time_dialog as dependency to pubspec.yaml file.

Example #

The code below returns a widget and can be added anywhere this is allowed. However it only returns an empty container (So it won't ruin your UI). It uses showDialog() to show the dialog.

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

OneTimeDialog(
  amountOfTimesToShow: 1,
  title: Text('Data policy'),
  content: Text('We are gathering personal data about you!'),
  actions: <Widget>[
    new FlatButton(onPressed: () => Navigator.pop(context), child: Text('OK'))
  ],
  context: context,
  id: 'AUniqueID',
),

Example gif #

Constructor (The ones unique for this packet) #

amountOfTimesToShow => Amount of times for the widget to be shown. Give this a value of 0 to keep showing (Works with offset).
id => An ID that is used in sharedprefferences. Make this unique.
offset => To show the dialog within an offset. If the offset is 2, the dialog will only be shown every second time the package is trying to be build.

[0.1.1]

  • Updated pubspec.yaml description to comply with pub.dev guidelines about length.

[0.1.0]

  • Second release
  • Fixed small problems addressed by the pub.dev score.

[0.0.1]

  • Initial Release

example/README.md

example #

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


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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example'),
        centerTitle: true,
      ),
      body: new Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          // Reload button.
          new Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new RaisedButton(onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => MyHomePage())), child: Text('Reload page!')),
            ],
          ),
          // The dialog
          OneTimeDialog(
            amountOfTimesToShow: 0,
            title: Text('Data policy'),
            content: Text('We are gathering personal data about you!'),
            actions: <Widget>[
              new FlatButton(onPressed: () => Navigator.pop(context), child: Text('OK'))
            ],
            context: context,
            id: 'AUniqueID1',
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  one_time_dialog: ^0.1.1

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:one_time_dialog/one_time_dialog.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]
100
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
shared_preferences ^0.5.3+1 0.5.3+4
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test