未处理的异常:FormatException:无效的基数 10 数字(在字符 1 处) [英] Unhandled Exception: FormatException: Invalid radix-10 number (at character 1)

查看:132
本文介绍了未处理的异常:FormatException:无效的基数 10 数字(在字符 1 处)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 net ninja 的这个 flutter 初学者教程here .但是我在斯里兰卡的时区 UTC +5:30 所以我尝试添加半小时,但它不断收到我无法修复的错误.如果可以,请帮助我!!

I was following this flutter beginner tutorial from net ninja here .But my timezone UTC +5:30 in Sri Lanka so i tried to add the half an hour but it keep getting this error that I cant fix. Please help me if you can!!.

完整回溯错误:

Performing hot restart...
Syncing files to device AOSP on IA Emulator...
Restarted application in 797ms.
E/flutter (31824): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FormatException: Invalid radix-10 number (at character 1)
E/flutter (31824): 5:3
E/flutter (31824): ^
E/flutter (31824): 
E/flutter (31824): #0      int._throwFormatException (dart:core-patch/integers_patch.dart:131:5)
E/flutter (31824): #1      int._parseRadix (dart:core-patch/integers_patch.dart:142:16)
E/flutter (31824): #2      int._parse (dart:core-patch/integers_patch.dart:100:12)
E/flutter (31824): #3      int.parse (dart:core-patch/integers_patch.dart:63:12)
E/flutter (31824): #4      WorldTime.getTime (package:world_time_app/services/world_time.dart:24:39)
E/flutter (31824): <asynchronous suspension>
E/flutter (31824): #5      _LoadingState.SetupWorldTime (package:world_time_app/pages/loading.dart:14:3)
E/flutter (31824): <asynchronous suspension>
E/flutter (31824): 

代码:

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

class WorldTime{

  String location;
  String time;
  String flag;
  String url;

  WorldTime({this.location, this.flag, this.url});

  Future<void> getTime() async{

    Response response = await get('https://www.worldtimeapi.org/api/timezone/$url');
    Map data = jsonDecode(response.body.toString());
    //print(data);
    String datetime = data['datetime'];
    String offset = data['utc_offset'].substring(2,5);
    //print(dataTime);
    //print(offset);
    DateTime now = DateTime.parse(datetime);
    now = now.add(Duration(hours: int.parse(offset)));

    time = now.toString();
    print(time);



  }

}

推荐答案

就我而言,我在权限参数中传递子路由,如下所示:

In my case I was passing subroutes inside authority parameter, like this:

var response =
          await http.get(Uri.https('https://favqs.com/api/quotes/', '4'), headers: {
        'Content-Type': 'application/json',
        'Authorization': "Token token='xxxxxxxxxxxxxxxx'",
      });

但是在删除 https 并将 /api/quotes/ 移到第二个参数后,问题就解决了.

but after removing https and moving /api/quotes/ in the second parameter, the issue got solved.

var response =
          await http.get(Uri.https('favqs.com', '/api/quotes/4'), headers: {
        'Content-Type': 'application/json',
        'Authorization': "Token token='xxxxxxxxxxxxxxxx'",
      });

这篇关于未处理的异常:FormatException:无效的基数 10 数字(在字符 1 处)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆