【问题标题】:world time api in flutterFlutter 中的世界时间 API
【发布时间】:2021-07-26 03:54:45
【问题描述】:

这是颤振应用程序的一部分。这个应用程序是显示城市的时间

错误发生在 api 的 url 中

Response response = await get(Uri.http('http://worldtimeapi.org', '/api/timezone/Asia/Karachi'));

错误消息是这里 基数为 10 的数字无效

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'dart:convert';

class Loading extends StatefulWidget {
  @override
  _LoadingState createState() => _LoadingState();
}

Map data;

class _LoadingState extends State<Loading> {
  getData() async {
    Response response = await get(
        Uri.http('http://worldtimeapi.org', '/api/timezone/Asia/Karachi'));
    print(response.body);
    await (data = jsonDecode(response.body));
    print(data);
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: Column(
        children: [
          Text('the data will on second hot restart like on ctrl+s'),
                  ],
      )),
    );
  }
}

【问题讨论】:

  • 从 URL 中删除 http://。 => Uri.http('worldtimeapi.org', '/api/timezone/Asia/Karachi')
  • 请复制粘贴完整的错误信息。
  • 这是完整的错误

标签: api flutter dart


【解决方案1】:

您不应在Uri.http 构造函数的权限字符串中包含协议。

Response response = await get(Uri.http('worldtimeapi.org', '/api/timezone/Asia/Karachi'));

【讨论】:

    猜你喜欢
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多