Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created January 12, 2019 19:01
Show Gist options
  • Save xsahil03x/bf5d17df9d67fe5e0450885ad43454dd to your computer and use it in GitHub Desktop.
Save xsahil03x/bf5d17df9d67fe5e0450885ad43454dd to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Result result;
TextEditingController userInput = TextEditingController();
var displayResult = '';
var isLoading = false;
Future<Null> _getResult(String input) async {
var response = await http.get(
Uri.encodeFull('http://coupondemoz.tk/sq/' + input),
headers: {"Accept": "application/json"});
if (response.statusCode == 200) {
var jsonData = json.decode(response.body);
Result r = Result.fromJson(jsonData);
print(r.result);
setState(() {
result = r;
});
return null;
} else {
throw Exception('Failed to load result');
}
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 40.0),
),
Padding(
padding: EdgeInsets.all(20.0),
child: TextField(
controller: userInput,
decoration: InputDecoration(
labelText: 'Enter URL',
hintText: 'Enter URL AS instagram.com/sasd',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)))),
),
new RaisedButton(
child: new Text('Make Request'),
onPressed: () {
_getResult(userInput.text);
}),
SizedBox(height: 10.0),
Text(
userInput.text.isNotEmpty
? "Your Result is ${result.result}"
: "Please Enter Details to check",
),
],
));
}
}
class Result {
String num;
String result;
Result({this.num, this.result});
Result.fromJson(Map<String, dynamic> json) {
num = json['Num'];
result = json['result'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['Num'] = this.num;
data['result'] = this.result;
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment