Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

android - Invalid radix-10 number (at character 1) 1: ^ by returning back to Home Screen in Flutter App

Invalid radix-10 number (at character 1) 1: ^ by returning back to Home Screen in Flutter App.

I'm trying to build an app World Time using Flutter.

This is the complete code in which I'm trying to accomplish the results.

This is the code given below of Home screen.

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
  Map data = {};
  @override
  Widget build(BuildContext context) {
    data = data.isNotEmpty ? data : ModalRoute.of(context).settings.arguments;

    String bgImage = int.parse(data['time'].substring(0,2))>07 && int.parse(data['time'].substring(0,2))<20 ? 'day.png' : 'night.png';
    Color bgColor = int.parse(data['time'].substring(0,2))>07 && int.parse(data['time'].substring(0,2))<20 ? Colors.blue : Colors.indigo[700];
    return Scaffold(
      backgroundColor: bgColor,
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage('assets/$bgImage'),
            fit: BoxFit.cover,
          ),
        ),
        alignment: Alignment.center,
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children:[
              FlatButton.icon(
                  icon: Icon(
                    Icons.location_pin,
                    color: Colors.grey[200],
                  ),
                  label: Text(
                    'Choose Location',
                    style: TextStyle(
                      color: Colors.grey[200],
                    ),
                  ),
                  onPressed: () async {
                    dynamic result = await Navigator.pushNamed(context, '/choose_location');
                    setState(() {
                      data = {
                        'time': result['time'],
                        'location': result['location'],
                        'flag': result['flag'],
                      };
                    });
                  }),
              Text(data['time'],
                style: TextStyle(
                  fontSize: 66.0,
                  color: Colors.white,
                ),
              ),
              SizedBox(height: 15),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    data['location'],
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 29.0,
                      letterSpacing: 2.0,
                    ),
                  ),
                ],
              ),
              SizedBox(height: 20),
            ]
        ),
      ),
    );
  }
}

This is the WorldTime Dart file code.

    class WorldTime {
      String location; //location name of the UI
      String time; //the time in that location
      String flag; //url to the asset flag icon
      String url; //location url for API endpoint    
      WorldTime({this.location, this.flag, this.url});
Future <void> getTime() async {
    try{
      Response response = await get('http://worldtimeapi.org/api/timezone/$url');
      Map data = jsonDecode(response.body);      
      String datetime = data['datetime'];
      String offset = data['utc_offset'].substring(1,3);
      DateTime now = DateTime.parse(datetime);
      now = now.add(Duration(hours: int.parse(offset)));
      time = DateFormat.jm().format(now);
    }
    catch(e){
      print('Caught error: $e');
      time = 'Could not get time data';
    }
    
      }
    }

This is the error I am getting: Error

question from:https://stackoverflow.com/questions/66059982/invalid-radix-10-number-at-character-1-1-by-returning-back-to-home-screen-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...