小编dea*_*zvi的帖子

如何在 Flutter 中一段时间​​不活动后执行函数

我需要创建一个应用程序,在一段时间不活动后将用户导航到。

我尝试将我的应用程序包装在 GestureDetector 中并在指定时间段后运行计时器,如下所示,但它不起作用:

class _MyAppState extends State<MyApp> {
  Timer _timer;

  @override
  void initState() {
    super.initState();

    _initializeTimer();
  }

  void _initializeTimer() {
    _timer = Timer.periodic(const Duration(seconds: 20), (_) => _logOutUser);
  }

  void _logOutUser() {
Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => WelcomePage()));
    _timer.cancel();
  }

  void _handleUserInteraction([_]) {
    if (!_timer.isActive) {
      return;
    }

    _timer.cancel();
    _initializeTimer();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: _handleUserInteraction,
      onPanDown: _handleUserInteraction,
      child: MaterialApp(
        title: 'Hello',
        home: WelcomePage(),
        routes: <String, WidgetBuilder>{
          '/welcome': (BuildContext context) => new WelcomePage(),
          '/login': …
Run Code Online (Sandbox Code Playgroud)

timer dart flutter

10
推荐指数
3
解决办法
6594
查看次数

将一些json字符串的值转换为php中的整数

我有以下PHP代码:

$data = array(
'id' => $_POST['id'],
'name' => $_POST['name'],
'country' => $_POST['country'],
'currency' => $_POST['currency'],
'description' => $_POST['description']
);

$data_string = json_encode($data);
Run Code Online (Sandbox Code Playgroud)

示例JSON如下:

{
 "id":"7",
 "name":"Dean",
 "country":"US",
 "currency":"840",
 "description":"Test"      
}
Run Code Online (Sandbox Code Playgroud)

我需要将"id"字段设为整数,并将"currency"保留为字符串,以便JSON成为:

 {
 "id":7,
 "name":"Dean",
 "country":"US",
 "currency":"840",
 "description":"Test"      
}
Run Code Online (Sandbox Code Playgroud)

我试过用:

$data_string = json_encode($data, JSON_NUMERIC_CHECK);
Run Code Online (Sandbox Code Playgroud)

但它也将"货币"变为整数.

有什么方法可以使"id"成为整数并将货币作为字符串.

php arrays json

7
推荐指数
1
解决办法
111
查看次数

如何在Dart中获取字符串中的最后n个字符?

如何获取字符串中的最后n个字符?

我试过使用:

var string = 'Dart is fun';
var newString = string.substring(-5);
Run Code Online (Sandbox Code Playgroud)

但这似乎并不正确

dart flutter

1
推荐指数
4
解决办法
2022
查看次数

标签 统计

dart ×2

flutter ×2

arrays ×1

json ×1

php ×1

timer ×1