import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Call a Function Everytime When App Starts')),
body: Center(
child: Alert()
)
)
);
}
}
class Alert extends StatefulWidget {
AlertState createState() => AlertState();
}
class AlertState extends State {
@override
void initState() {
showAlert(context);
super.initState();
}
Future showAlert(BuildContext context) async {
await Future.delayed(Duration(seconds: 6));
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('Welcome To Our App :) .'),
actions: <Widget>[
FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Call A Function Automatically When App Starts Everytime',
style: TextStyle(fontSize: 22,), textAlign: TextAlign.center,)
),
);
}
}