Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在Flatter中切换应用程序后如何保持静态变量值?_Flutter_Dart - Fatal编程技术网

Flutter 在Flatter中切换应用程序后如何保持静态变量值?

Flutter 在Flatter中切换应用程序后如何保持静态变量值?,flutter,dart,Flutter,Dart,我有一个Flitter应用程序,通过调用url使用打印机。url调用打开另一个名为passPRNT的应用程序,该应用程序执行打印作业,然后passPRNT调用myappschema://another-url-with-results?var=val. 问题是打印后静态变量丢失或重新启动,因此我无法跟踪打印的内容 我有一门印刷课。dart: class Print { static bool printing = false; } 然后在main.dart中: if (!Print.pri

我有一个Flitter应用程序,通过调用url使用打印机。url调用打开另一个名为passPRNT的应用程序,该应用程序执行打印作业,然后passPRNT调用myappschema://another-url-with-results?var=val.

问题是打印后静态变量丢失或重新启动,因此我无法跟踪打印的内容

我有一门印刷课。dart:

class Print {
  static bool printing = false;
}
然后在main.dart中:

if (!Print.printing)
{
  // this should only happen once
  // but since the value of Print.printing seems to reset when my app comes back to focus
  // this print job repeats forever
  Print.printing = true;
  openPassPRNTurl();
}

在类的局部变量中可以有flage值,这样该变量将管理它的状态

class SomeScreen extends StatefulWidget {
  static bool printing = Print.printing;
  @override
  State<StatefulWidget> createState() { 
    if ( !printing)
    { 
       printing = true;
      print("Hellooooo");
    }
    return _SomeScreenState();
  }
}
class SomeScreen扩展StatefulWidget{
静态布尔打印=Print.printing;
@凌驾
状态createState(){
如果(!打印)
{ 
打印=正确;
印刷品(“你好”);
}
返回_SomeScreenState();
}
}

将它们保存在设备上,并在应用程序启动后还原reopenned@R你是说弗利特应该这样做?当然,我已经考虑过这个解决方案,但这让我对颤振非常失望。@RobinManoli您可以创建局部变量来管理颤振的状态flag@AnkitMahadik你能详细说明一下吗?你是什么意思?@RobinManoli请检查我的答案,也许这就是你想要的答案