Flutter 我如何在flifter中在类外运行void命令

Flutter 我如何在flifter中在类外运行void命令,flutter,dart,mqtt,Flutter,Dart,Mqtt,当我自动启动程序时,我试图运行一个无效代码(写在类内部) void _configureAndConnect() { String _named = null; String _topnamed = null; String osPrefix = 'Commander'; if (Platform.isAndroid) { osPrefix = 'NotCommander'; } if ( _name.isEmpty) {

当我自动启动程序时,我试图运行一个无效代码(写在类内部)

void _configureAndConnect() {
    String _named  = null;
    String _topnamed = null;
    String osPrefix = 'Commander';
    if (Platform.isAndroid) {
      osPrefix = 'NotCommander';
    }
    if ( _name.isEmpty) {
      _named = _hostTextController.text;
    }else {_named = _name;}

    if ( _topname.isEmpty) {
      _topnamed = _topicTextController.text;
    }else {_topnamed = _topname;}
    manager = MQTTManager(
      //  _name.isEmpty ? host: _buildTextFieldWith.text, host: _buildTextFieldWith.text : _name,

        host: _named,

        topic: _topnamed,
        identifier: osPrefix,
        state: currentAppState);
    manager.initializeMQTTClient();
    manager.connect();
  }
这是我在一个类中的代码。 我想在自动打开应用程序时运行它。
谢谢。

你在你的应用程序主页上运行它吗?我只有一个main.dart页面,上面有所有内容。将它放在与
main()
相同的级别,并在
main()内调用它
runApp()之前
import
和injector是什么意思?你的意思是我可以在runApp()之前将所有无效代码放在main()中?