'i try to make a navigator to sign in page in flutter, but thet say it doesn't have a constant constructor

class _SplashpageState extends State<Splashpage> {
  @override
  void initState() {

Timer(Duration(seconds: 3),
() => const Navigator.pushNamed(context, '/sign-in'),
);
super.initState();
}

I already see some tutorials on youtube, but it didn't work, please give some tips how to solve this problem



Solution 1:[1]

Try removing const which is in front of const Navigator.pushNamed(context, '/sign-in'),

class _SplashpageState extends State<Splashpage> {
  @override
  void initState() {
    Timer(
      Duration(seconds: 3),
      () => Navigator.pushNamed(context, '/sign-in'),
    );
    super.initState();
  }
  
  // ...
}

Navigator.pushNamed is a static method, not a constructor (and therefore, not a const constructor) so it doesn't make sense to use const there.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Valentin Vignal