1

I want to pass a variable from a statelesswidget to a stateful widget. But when I do so, i have to remove the const from the constructor of GameScreen. Which is generally not advised and will make the statelesswidget equivalent to a stateful widget interms of system resources(since it will be a variable and not a const), is there any other way i can do it?

code:

class GameScreen extends StatelessWidget {
  const GameScreen({Key? key}) : super(key: key);

  final gameState = Get.find<SudokuGame>();  

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: ExampleGameScreenUI(),//I want to send gameState as a parameter to ExampleGameScreenUI
    );
  }
}
Joel
  • 239
  • 3
  • 21
  • I don't think that removing the `const` keyword will make the stateless widget equivalent to a stateful widget. Did you check the documentation for it? – Viraj Doshi Nov 24 '21 at 03:58
  • @VirajD can u send the link? in other languages it makes a stateless object update everytime – Joel Nov 24 '21 at 03:59
  • I don't know about other languages or frameworks but Stateless widget cannot update anytime in flutter. Only stateful widgets can be updated – Viraj Doshi Nov 24 '21 at 04:02
  • @VirajD https://stackoverflow.com/questions/69341612/can-i-remove-const-in-the-below-flutter-code, i don't think it is safe to remove the const from the constructor – Joel Nov 24 '21 at 14:28
  • 1
    it is still completely safe to remove the `const` keyword. The `const` keyword helps flutter know that a widget is constant and should not be rebuild, this helps in performance. Removing 1 `const` keyword will not make any difference in the performance and the app will run just fine. – Viraj Doshi Nov 25 '21 at 03:50

0 Answers0