Hope everythign is fine.
I am new to flutter.
I want to call a method on load ?
I tired
void initState() {
super.initState();
log('Load Event');
}
But it is not working ?
Any chance
Here is my full code
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'dart:developer';
import 'package:flutter/scheduler.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo ',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Position _currentPosition;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Trex Partner Finder hh"),
),
body: Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/TrexIcon.png"),
fit: BoxFit.scaleDown,
),
),
),
floatingActionButton:
FloatingActionButton.extended(
onPressed: () {
_getCurrentLocation();
},
label: Text(" Find Partner Alooo "),
),
);
}
void initState() {
super.initState();
log('h');
}
_getCurrentLocation() {
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position) {
setState(() {
_currentPosition = position;
});
}).catchError((e) {
print(e);
});
log(_currentPosition.longitude.toString());
log(_currentPosition.latitude.toString());
}
}
@override void initState() { print('h'); super.initState(); }