0

I'm stuck with this error:

This expression has type 'void' and can't be used.
dynamic result = await context.pushNamed('location');                            î 
                               î
This expression has type 'void' and can't be used.
dynamic result = await context.pushNamed('location');
                 î

home.dart

onPressed: () async {                            
    dynamic result = await context.pushNamed('location');
    setState(() {
        mydata = result;
    }); 
},


       î       

location.dart

class _LocationState extends State<Location> {
    ...

  void updateTime(index) async {
      WorldTime instance = locations[index];
      await instance.getTime();
      context.goNamed('home', extra: instance);
  }
}

world_time.dart

class WorldTime {
    ...

  Future<void> getTime() async {
    ...

  }
}

I use go_router but I don't know if it has anything to do with my problem.
I tried: Future<void> updateTime(index) async { but I'm still getting the same error.

Duddy67
  • 836
  • 2
  • 10
  • 26

1 Answers1

0

It turns out that it's not possible to navigate to a new screen and back through push() and pop() with go_router, according to that post.
So my best bet here is to use the native Navigator.

home.dart

onPressed: () async {                            
    dynamic result = await Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => Location()),
    );

    setState(() {
        mydata = result;
    }); 
},

location.dart

class _LocationState extends State<Location> {
    ...

  void updateTime(index) async {
      WorldTime instance = locations[index];
      await instance.getTime();

      Navigator.pop(context, instance);
  }
}
Duddy67
  • 836
  • 2
  • 10
  • 26