Home > OS >  Calling Future inside another class
Calling Future inside another class

Time:05-14

Future determinePosition

class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  Position currentposition;

  Future<Position> _determinePosition() async{
  ...

GestureDetector onTap

class CurrentWeather extends StatefulWidget {
  @override
}

class _CurrentWeatherState extends State<CurrentWeather> {

  @override

  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        _determinePosition();
          });
        }
      },

I need to call Future determinePosition, which appears in the top code snippet, on the onTap of GestureDetector, which appears in the bottom code snippet, but I can't do it somehow

CodePudding user response:

You should any state managment like provider.

https://pub.dev/packages/provider

CodePudding user response:

that is a very bad practice. you should use a state management package like Provider or GetX.

  • Related