Commit 3b8b2765 authored by qorri_di's avatar qorri_di

Consume API

- consume api
parent 33b15759
...@@ -3,7 +3,7 @@ import 'dart:convert'; ...@@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:medapp_eksad/model/contact_model.dart'; import 'package:medapp_eksad/model/contact_model.dart';
Future<bool> savecontact(nama, email, nohp, message) async { Future savecontact(nama, email, nohp, message) async {
final response = await http.post( final response = await http.post(
Uri.parse('http://10.107.121.210:8081/medapp/v1/api/contact/save'), Uri.parse('http://10.107.121.210:8081/medapp/v1/api/contact/save'),
body: jsonEncode({ body: jsonEncode({
...@@ -14,11 +14,11 @@ Future<bool> savecontact(nama, email, nohp, message) async { ...@@ -14,11 +14,11 @@ Future<bool> savecontact(nama, email, nohp, message) async {
headers: { headers: {
'Content-type': 'application/json; charset=UTF-8', 'Content-type': 'application/json; charset=UTF-8',
}); });
if (response.statusCode == 200) { // if (response.statusCode == 200) {
return true; // return true;
} else { // } else {
return false; // return false;
} // }
} }
Future<List<contact>> showcontact() async { Future<List<contact>> showcontact() async {
......
...@@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart'; ...@@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
// import 'package:mcs_flutter/const/conts.dart'; // import 'package:mcs_flutter/const/conts.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:medapp_eksad/api/contact_api.dart';
import 'package:medapp_eksad/widget/button_color.dart'; import 'package:medapp_eksad/widget/button_color.dart';
class ContactUs2 extends StatelessWidget { class ContactUs2 extends StatelessWidget {
...@@ -251,10 +252,10 @@ class ContactUs2 extends StatelessWidget { ...@@ -251,10 +252,10 @@ class ContactUs2 extends StatelessWidget {
style: Btn_Submit(), style: Btn_Submit(),
onPressed: () async { onPressed: () async {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
final response = await SendEmail( final response = await savecontact(
nameController.value.text, nameController.value.text,
phoneController.value.text,
emailController.value.text, emailController.value.text,
phoneController.value.text,
messageController.value.text); messageController.value.text);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
response == 200 response == 200
...@@ -289,28 +290,4 @@ class ContactUs2 extends StatelessWidget { ...@@ -289,28 +290,4 @@ class ContactUs2 extends StatelessWidget {
), ),
); );
} }
Future SendEmail(
String name, String phone, String email, String message) async {
final url = Uri.parse('https://api.emailjs.com/api/v1.0/email/send');
const serviceId = 'service_wava70j';
const templateId = 'template_koc73cj';
const userId = 'h4BmDnyWlm3OziBDx';
final response = await http.post(url,
headers: {
'Content-Type': 'application/json'
}, //This line makes sure it works for all platforms.
body: json.encode({
'service_id': serviceId,
'template_id': templateId,
'user_id': userId,
'template_params': {
'from_name': name,
'from_phone': phone,
'to_email': email,
'message': message
}
}));
return response.statusCode;
}
} }
...@@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart'; ...@@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
// import 'package:mcs_flutter/const/conts.dart'; // import 'package:mcs_flutter/const/conts.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:medapp_eksad/api/contact_api.dart';
import 'package:medapp_eksad/widget/button_color.dart'; import 'package:medapp_eksad/widget/button_color.dart';
...@@ -232,10 +233,10 @@ class _ContactUs2_smallState extends State<ContactUs2_small> { ...@@ -232,10 +233,10 @@ class _ContactUs2_smallState extends State<ContactUs2_small> {
style: Btn_Submit(), style: Btn_Submit(),
onPressed: () async { onPressed: () async {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
final response = await SendEmail( final response = await savecontact(
nameController.value.text, nameController.value.text,
phoneController.value.text,
emailController.value.text, emailController.value.text,
phoneController.value.text,
messageController.value.text); messageController.value.text);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
response == 200 response == 200
...@@ -267,30 +268,6 @@ class _ContactUs2_smallState extends State<ContactUs2_small> { ...@@ -267,30 +268,6 @@ class _ContactUs2_smallState extends State<ContactUs2_small> {
), ),
); );
} }
Future SendEmail(
String name, String phone, String email, String message) async {
final url = Uri.parse('https://api.emailjs.com/api/v1.0/email/send');
const serviceId = 'service_wava70j';
const templateId = 'template_koc73cj';
const userId = 'h4BmDnyWlm3OziBDx';
final response = await http.post(url,
headers: {
'Content-Type': 'application/json'
}, //This line makes sure it works for all platforms.
body: json.encode({
'service_id': serviceId,
'template_id': templateId,
'user_id': userId,
'template_params': {
'from_name': name,
'from_phone': phone,
'to_email': email,
'message': message
}
}));
return response.statusCode;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment