Commit 04723573 authored by Budi Prasetyo's avatar Budi Prasetyo

push

parent 56fc8238
import 'dart:convert';
import 'package:http/http.dart' as http;
var cmd = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/cmd';
var qry = 'https://dmsdev-api.eksad.com/gateway/medapp/v1/qry';
Future<bool> createSosmed (wa, ln, tw, ig, yt) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveSettingSosmed'),
body: jsonEncode(
{
"whatsapp": wa,
"linkedin": ln,
"twitter": tw,
"instagram": ig,
"youtube": yt
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
});
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<bool> updateSosmed (wa,ln,tw,ig,yt) async {
final response = await http
.put(Uri.parse('$cmd/settingsosmed/updateSettingSosmed'),
body: jsonEncode({
'whatsapp': wa,
'linkedin': ln,
'twitter': tw,
'instagram': ig,
'youtube': yt
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
});
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<List<dynamic>> getSosmedDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getSettingSosmedById'));
// Uri.parse('$qry/settingsosmed/getSettingSosmedByIdDesc'));
return jsonDecode(response.body)['data'];
}
\ No newline at end of file
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:medapp_eksad/api/sosmed_api.dart';
class SosmedDashboard extends StatefulWidget { class SosmedDashboard extends StatefulWidget {
const SosmedDashboard({Key? key}) : super(key: key); const SosmedDashboard({Key? key}) : super(key: key);
...@@ -13,12 +14,20 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -13,12 +14,20 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
var btnText = 'Save Setting'; var btnText = 'Save Setting';
var enb = true; var enb = true;
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
final waController = TextEditingController();
TextEditingController waController = new TextEditingController();
// final waController = TextEditingController();
final linkedController = TextEditingController(); final linkedController = TextEditingController();
final twitterController = TextEditingController(); final twitterController = TextEditingController();
final igController = TextEditingController(); final igController = TextEditingController();
final youtubeController = TextEditingController(); final youtubeController = TextEditingController();
String wa = '';
String ln = '';
String tw ='';
String ig = '';
String yt = '';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var screenSize = MediaQuery.of(context).size; var screenSize = MediaQuery.of(context).size;
...@@ -34,6 +43,7 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -34,6 +43,7 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
const EdgeInsets.only(left: 30, top: 15, right: 30, bottom: 15), const EdgeInsets.only(left: 30, top: 15, right: 30, bottom: 15),
color: Colors.white, color: Colors.white,
child: Form( child: Form(
key: formKey,
child: Column( child: Column(
children: [ children: [
Row( Row(
...@@ -45,10 +55,6 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -45,10 +55,6 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
fontSize: 25, fontSize: 25,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
letterSpacing: 1.1)), letterSpacing: 1.1)),
// SizedBox(
// height: 0,
// width: 820,
// ),
ElevatedButton( ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
...@@ -59,22 +65,47 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -59,22 +65,47 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
onPressed: () { onPressed: () {
switch (btnText) { switch (btnText) {
case 'Save Setting': case 'Save Setting':
// createSetting(im.toString(), tt.toString(),
// tl.toString(), em.toString(), no.toString()); createSosmed(wa, ln, tw, ig, yt);
{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),));
}
// waController.clear();
// linkedController.clear();
// twitterController.clear();
// igController.clear();
// youtubeController.clear();
// createSetting(im.toString(), tt.toString(),
// tl.toString(), em.toString(), no.toString());
setState(() { setState(() {
btnText = 'Update Setting'; btnText = 'Update Setting';
enb = false; enb = false;
}); }
);
break; break;
case 'Update Setting': case 'Update Setting':
// waController.clear();
// linkedController.clear();
// twitterController.clear();
// igController.clear();
// youtubeController.clear();
setState(() { setState(() {
enb = true; enb = true;
btnText = 'Save Update'; btnText = 'Save Update';
}); });
break; break;
case 'Save Update': case 'Save Update':
createSosmed(wa, ln, tw, ig, yt);
{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),));
}
break; break;
default: default:
createSosmed(wa, ln, tw, ig, yt);
{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),));
}
} }
}, },
child: Text( child: Text(
...@@ -108,6 +139,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -108,6 +139,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
decoration: InputDecoration( decoration: InputDecoration(
hintText: hintText:
'Enter WhatsApp number without +, Ex : 6280000000000 '), 'Enter WhatsApp number without +, Ex : 6280000000000 '),
onChanged: (value) => wa = value,
enabled: enb,
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -115,7 +148,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -115,7 +148,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content: Text('Nomer'), content:FutureBuilder<List<dynamic>>(
future: getSosmedDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return Text('Active WA : '+pgm['whatsapp']);
},
),
) , ) ,
); );
}, child: Text('View Active'))), }, child: Text('View Active'))),
...@@ -131,6 +175,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -131,6 +175,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
controller: linkedController, controller: linkedController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter a new Linkedin link address'), hintText: 'Enter a new Linkedin link address'),
onChanged: (value) => ln = value,
enabled: enb,
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -138,7 +184,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -138,7 +184,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content: Text('Linkedin'), content:FutureBuilder<List<dynamic>>(
future: getSosmedDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return Text('Active Linkedin : '+pgm['linkedin']);
},
),
) , ) ,
); );
}, child: Text('View Active'))), }, child: Text('View Active'))),
...@@ -154,6 +211,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -154,6 +211,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
controller: twitterController, controller: twitterController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter a new Twitter link address'), hintText: 'Enter a new Twitter link address'),
onChanged: (value) => tw = value,
enabled: enb,
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -161,7 +220,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -161,7 +220,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content: Text('Twitter'), content:FutureBuilder<List<dynamic>>(
future: getSosmedDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return Text('Active Twitter : '+pgm['twitter']);
},
),
) , ) ,
); );
}, child: Text('View Active'))), }, child: Text('View Active'))),
...@@ -177,6 +247,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -177,6 +247,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
controller: igController, controller: igController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter a new Instagram link address'), hintText: 'Enter a new Instagram link address'),
onChanged: (value) => ig = value,
enabled: enb,
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -184,7 +256,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -184,7 +256,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content: Text('Instagram'), content:FutureBuilder<List<dynamic>>(
future: getSosmedDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return Text('Active Instagram : '+pgm['instagram']);
},
),
) , ) ,
); );
}, child: Text('View Active'))), }, child: Text('View Active'))),
...@@ -200,6 +283,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -200,6 +283,8 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
controller: youtubeController, controller: youtubeController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter a new Youtube link address'), hintText: 'Enter a new Youtube link address'),
onChanged: (value) => yt = value,
enabled: enb,
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -207,7 +292,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -207,7 +292,18 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content: Text('Youtube'), content:FutureBuilder<List<dynamic>>(
future: getSosmedDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return Text('Active Youtube : '+pgm['youtube']);
},
),
) , ) ,
); );
}, child: Text('View Active'))), }, child: Text('View Active'))),
......
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