is_first_run 0.1.0 is_first_run: ^0.1.0 copied to clipboard
A simple package to check if it is the first time the app runs.
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(),
),
),
);
}
}