Commit d607485f authored by Fikri's avatar Fikri

menambahkan contact us untuk send email

parent b13e7f74
...@@ -5,7 +5,7 @@ import 'package:medapp_eksad/model/contact_model.dart'; ...@@ -5,7 +5,7 @@ import 'package:medapp_eksad/model/contact_model.dart';
Future 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.223.156:8081/medapp/v1/api/contact/save'),
body: jsonEncode({ body: jsonEncode({
"nama": nama, "nama": nama,
"email": email, "email": email,
...@@ -24,7 +24,7 @@ Future savecontact(nama, email, nohp, message) async { ...@@ -24,7 +24,7 @@ Future savecontact(nama, email, nohp, message) async {
Future<List<contact>> showcontact() async { Future<List<contact>> showcontact() async {
var response = await http var response = await http
.get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/contact/get')); .get(Uri.parse('http://10.107.223.156:8082/medapp/v1/api/contact/get'));
var resultJson = jsonDecode(response.body)['data']; var resultJson = jsonDecode(response.body)['data'];
List<contact> contactlist = await resultJson List<contact> contactlist = await resultJson
.map<contact>((json) => contact.fromJson(json)) .map<contact>((json) => contact.fromJson(json))
......
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
// import 'package:mcs_flutter/widget/botton.dart'; // import 'package:mcs_flutter/widget/botton.dart';
// import 'package:mcs_flutter/const/conts.dart'; // import 'package:mcs_flutter/const/conts.dart';
import 'package:http/http.dart' as http;
import 'package:medapp_eksad/api/contact_api.dart'; import 'package:medapp_eksad/api/contact_api.dart';
import 'package:medapp_eksad/widget/button_color.dart'; import 'package:medapp_eksad/widget/button_color.dart';
...@@ -250,7 +253,7 @@ class ContactUs2 extends StatelessWidget { ...@@ -250,7 +253,7 @@ 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 savecontact( final response = await SendEmail(
nameController.value.text, nameController.value.text,
emailController.value.text, emailController.value.text,
phoneController.value.text, phoneController.value.text,
...@@ -288,4 +291,28 @@ class ContactUs2 extends StatelessWidget { ...@@ -288,4 +291,28 @@ 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_7wwup8c';
const templateId = 'template_4u8rbur';
const userId = 'bzSFpP9flgDHE1D8dDLOP';
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;
}
} }
...@@ -234,7 +234,7 @@ class _ContactUs2_smallState extends State<ContactUs2_small> { ...@@ -234,7 +234,7 @@ 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 savecontact( final response = await SendEmail(
nameController.value.text, nameController.value.text,
emailController.value.text, emailController.value.text,
phoneController.value.text, phoneController.value.text,
...@@ -268,6 +268,30 @@ class _ContactUs2_smallState extends State<ContactUs2_small> { ...@@ -268,6 +268,30 @@ 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_7wwup8c';
const templateId = 'template_4u8rbur';
const userId = 'bzSFpP9flgDHE1D8dDLOP';
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