is_first_run 0.1.0 copy "is_first_run: ^0.1.0" to clipboard
is_first_run: ^0.1.0 copied to clipboard

outdated

A simple package to check if it is the first time the app runs.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:is_first_run/is_first_run.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,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'is_first_run 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> {
  bool _isFirstRun;

  void _checkFirstRun() async {
    bool ifr = await IsFirstRun.isFirstRun();
    setState(() {
      _isFirstRun = ifr;
    });
  }

  void _resetFirstRun() async {
    await IsFirstRun.reset();
    _checkFirstRun();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
                child: Text('Check if first run'), onPressed: _checkFirstRun),
            RaisedButton(child: Text('Reset'), onPressed: _resetFirstRun),
            (_isFirstRun != null)
                ? Text(
                    'Is first run: $_isFirstRun',
                  )
                : null,
          ].where((element) => element != null).toList(),
        ),
      ),
    );
  }
}
87
likes
40
pub points
95%
popularity

Publisher

verified publisherjulianassmann.de

A simple package to check if it is the first time the app runs.

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on is_first_run