Jake
Jake

Reputation: 2056

Flutter - Getting HTTP Response from url_launcher

In Flutter it's easy to take the user to a website using url_launcher (FIG A). I'm looking for a way to return a HTTP status code upon completion / failure. This would ideally be returned in a string for text output.

FIG A;

_launchURL() async {
  const url = 'https://google.com/';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

Thanks

Upvotes: 1

Views: 2921

Answers (1)

Andrii Turkovskyi
Andrii Turkovskyi

Reputation: 29458

import 'package:http/http.dart' as http;

void _loadFromUrl(String url) async {
  http.Response response = await http.get(url);
  if (response.statusCode == 200) {...}
  else {...}

I hope it'll help

Upvotes: 2

Related Questions