Organisations' names request implemented

This commit is contained in:
Felix 2019-07-08 11:17:45 +01:00
parent b1938df909
commit b986b3e574
2 changed files with 40 additions and 8 deletions

View file

@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
import 'package:local_spend/common/apifunctions/request_login_api.dart'; import 'package:local_spend/common/apifunctions/request_login_api.dart';
import 'package:local_spend/common/functions/show_dialog_single_button.dart'; import 'package:local_spend/common/functions/show_dialog_single_button.dart';
import 'package:local_spend/common/platform/platform_scaffold.dart'; import 'package:local_spend/common/platform/platform_scaffold.dart';
import 'package:local_spend/common/widgets/basic_drawer.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';

View file

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -9,6 +10,8 @@ import 'package:local_spend/common/widgets/basic_drawer.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:http/http.dart' as http;
import 'package:local_spend/common/functions/get_token.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart'; import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
const URL = "https://flutter.io/"; const URL = "https://flutter.io/";
@ -120,6 +123,39 @@ class ReceiptPageState extends State<ReceiptPage> {
return "false"; return "false";
} }
Future<String> findOrganisations(String search) async {
final url = "https://dev.peartrade.org/api/search";
var token;
await getToken().then((result) {
token = result;
});
Map<String, String> body = {
"search_name":search,
"session_key":token,
};
debugPrint(token.toString() + " " + json.encode(body).toString());
final response = await http.post (
url,
//{"search_name":"bo","session_key":"1C2AB5F0-A163-11E9-BE68-241789E69626"}
body: json.encode(body),
);
debugPrint(response.body);
debugPrint(response.statusCode.toString());
if (response.statusCode == 200) {
//request successful
return response.body;
} else {
return null;
}
}
String formatDate(String date) { String formatDate(String date) {
// return ""; // return "";
// should be in format: // should be in format:
@ -260,16 +296,13 @@ class ReceiptPageState extends State<ReceiptPage> {
Container( Container(
child : Padding( child : Padding(
padding: EdgeInsets.fromLTRB(5,0,0,4), padding: EdgeInsets.fromLTRB(5,0,0,4), // sorry about hardcoded constraints
child: FlatButton( child: FlatButton(
onPressed: () { onPressed: () {
debugPrint("TODO: 'find organisation' dialog"); debugPrint("TODO: 'find organisation' dialog");
// Writing this before I forget tomorrow morning:
// Steps to fetch list of organisations with similar name: findOrganisations(_orgController.text);
// 1) record network activity (requests) of FoodLoop-Web webapp on Firefox
// 2) look at JSON files returned by server when 'organisation name' field's text updates/changes
// 3) look at requests sent to server when web textfield updates and send those from app
// 4) I'm tired
}, },
child: Text("Find", child: Text("Find",
style: style: