Commit 38baf053 authored by Ade Fikriatul  Ilmi's avatar Ade Fikriatul Ilmi

menambahkan get and put per column

parent e430a69a
...@@ -26,11 +26,11 @@ Future<bool> createSosmed (wa, ln, tw, ig, yt) async{ ...@@ -26,11 +26,11 @@ Future<bool> createSosmed (wa, ln, tw, ig, yt) async{
} }
} }
Future<bool> updateSosmed (wa, ln, tw, ig, yt) async { Future<bool> updateSosmed (id, wa, ln, tw, ig, yt) async {
final response = await http final response = await http
.put(Uri.parse('$cmd/settingsosmed/saveSettingSosmed'), .post(Uri.parse('$cmd/settingsosmed/saveSettingSosmed'),
body: jsonEncode({ body: jsonEncode({
// 'idSettingSosmed': id, 'idSettingSosmed': id,
'whatsapp': wa, 'whatsapp': wa,
'linkedin': ln, 'linkedin': ln,
'twitter': tw, 'twitter': tw,
...@@ -54,3 +54,140 @@ Future<List<dynamic>> getSosmedDesc() async { ...@@ -54,3 +54,140 @@ Future<List<dynamic>> getSosmedDesc() async {
Uri.parse('$qry/settingsosmed/getSettingSosmedByIdDesc')); Uri.parse('$qry/settingsosmed/getSettingSosmedByIdDesc'));
return jsonDecode(response.body)['data']; return jsonDecode(response.body)['data'];
} }
Future<bool> createWA (wa) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveWhatsapp'),
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> createLN (ln) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveLinkedin'),
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> createTW (tw) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveTwitter'),
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> createIG (ig) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveInstagram'),
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> createYT (yt) async{
final response = await http.post(
Uri.parse('$cmd/settingsosmed/saveYoutube'),
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>> getWaDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getWhatsappByIdDesc'));
return jsonDecode(response.body)['data'];
}
Future<List<dynamic>> getLnDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getLinkedinByIdDesc'));
return jsonDecode(response.body)['data'];
}
Future<List<dynamic>> getTwDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getTwitterByIdDesc'));
return jsonDecode(response.body)['data'];
}
Future<List<dynamic>> getIgDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getInstagramByIdDesc'));
return jsonDecode(response.body)['data'];
}
Future<List<dynamic>> getYtDesc() async {
var response = await http.get(
Uri.parse('$qry/settingsosmed/getYoutubeByIdDesc'));
return jsonDecode(response.body)['data'];
}
\ No newline at end of file
...@@ -29,6 +29,7 @@ Future<bool> signUp(namars,nors,alamatrs,namapic,nopic,email, password)async{ ...@@ -29,6 +29,7 @@ Future<bool> signUp(namars,nors,alamatrs,namapic,nopic,email, password)async{
} }
// return response.statusCode; // return response.statusCode;
} }
Future<bool> signIn(username, password)async{ Future<bool> signIn(username, password)async{
final response = await http.post( final response = await http.post(
Uri.parse('$cmd/user/signin'), Uri.parse('$cmd/user/signin'),
......
...@@ -15,19 +15,22 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -15,19 +15,22 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
var enb = true; var enb = true;
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
TextEditingController waController = new TextEditingController(); //TextEditingController waController = new TextEditingController();
// final waController = 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 wa = '';
String ln = ''; String ln = '';
String tw =''; String tw ='';
String ig = ''; String ig = '';
String yt = ''; String yt = '';
String pattern = r'(\62)(\d{2,3})?\)?[ .-]?\d{2,4}[ .-]?\d{2,4}[ .-]?\d{2,4}';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var screenSize = MediaQuery.of(context).size; var screenSize = MediaQuery.of(context).size;
...@@ -35,7 +38,7 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -35,7 +38,7 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
color: const Color.fromRGBO(238, 224, 224, 1), color: const Color.fromRGBO(238, 224, 224, 1),
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: screenSize.width * 0.05, horizontal: screenSize.width * 0.05,
vertical: screenSize.height * 0.05), vertical: screenSize.height * 0.04),
child: Container( child: Container(
width: screenSize.width, width: screenSize.width,
height: screenSize.height * 0.8, height: screenSize.height * 0.8,
...@@ -62,14 +65,37 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -62,14 +65,37 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
), ),
primary: const Color.fromARGB(255, 0, 67, 192), primary: const Color.fromARGB(255, 0, 67, 192),
), ),
onPressed: () { onPressed: () async {
switch (btnText) { switch (btnText) {
case 'Save Setting': case 'Save Setting':
createSosmed(wa, ln, tw, ig, yt); if (formKey.currentState!.validate()) {
{ // await updateSosmed(wa, ln, tw, ig, yt);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),)); // await createSosmed(wa, ln, tw, ig, yt);
await createWA(wa);
await createLN(ln);
await createTW(tw);
await createIG(ig);
await createYT(yt);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Data Saved'),
backgroundColor: Colors.green)
);
}else if(formKey.currentState!.validate()){}
else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to save data, please edit all field'),
backgroundColor: Colors.red)
);
} }
// waController.clear(); // waController.clear();
// linkedController.clear(); // linkedController.clear();
// twitterController.clear(); // twitterController.clear();
...@@ -96,16 +122,35 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -96,16 +122,35 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
}); });
break; break;
case 'Save Update': case 'Save Update':
createSosmed(wa, ln, tw, ig, yt); if (formKey.currentState!.validate()) {
{ // await updateSosmed(wa, ln, tw, ig, yt);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),)); // await createSosmed(wa, ln, tw, ig, yt);
await createWA(wa);
await createLN(ln);
await createTW(tw);
await createIG(ig);
await createYT(yt);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Data Saved'),
backgroundColor: Colors.green)
);
}else if(formKey.currentState!.validate()){}
else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to save data, please edit all field'),
backgroundColor: Colors.red)
);
} }
break; break;
default: default:
createSosmed(wa, ln, tw, ig, yt);
{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Save Data Success'),));
}
} }
}, },
child: Text( child: Text(
...@@ -123,24 +168,66 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -123,24 +168,66 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
// endIndent: 0, // endIndent: 0,
color: Colors.grey, color: Colors.grey,
), ),
SizedBox( // Text('Data Must Be Edited'),
height: 25, // Text('For data that is not modified, Please copy last data , delete then paste again'),
const SizedBox(
height: 10,
), ),
// 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
// },
// ),
Column( Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
listsosmed( FutureBuilder<List<dynamic>>(
Icon( future: getWaDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0];
if (snapshot.hasError ||
snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
return listsosmed(
const Icon(
Icons.whatsapp, Icons.whatsapp,
color: Colors.green, color: Colors.green,
), ),
TextFormField( TextFormField(
controller: waController, controller: waController..text = pgm['whatsapp'],
decoration: InputDecoration(
//initialValue: pgm['whatsapp'],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.red),
hintText: hintText:
'Enter WhatsApp number without +, Ex : 6280000000000 '), 'Enter WhatsApp number without +, Ex : 6280000000000 ',
helperText: 'Enter WhatsApp number without +, Ex : 6280000000000 ',
),
onChanged: (value) => wa = value, onChanged: (value) => wa = value,
enabled: enb, enabled: enb,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your phone number';
}else if(!RegExp(pattern).hasMatch(value)){
return 'Please enter with 628 only';
}
return null;
},
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -148,35 +235,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -148,35 +235,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content:FutureBuilder<List<dynamic>>( content:Text('Active WA : '+pgm['whatsapp'])
future: getSosmedDesc(), ) ,
);
}, child: const Text('View Active')));
},
),
const SizedBox(
height: 10,
),
FutureBuilder<List<dynamic>>(
future: getLnDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0]; var pgm = snapshot.data[0];
if (snapshot.hasError || if (snapshot.hasError ||
snapshot.data == null || snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) { snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
} }
return Text('Active WA : '+pgm['whatsapp']); return listsosmed(
}, const Icon(
),
) ,
);
}, child: Text('View Active'))),
SizedBox(
height: 10,
),
listsosmed(
Icon(
FontAwesomeIcons.linkedin, FontAwesomeIcons.linkedin,
color: Colors.blue, color: Colors.blue,
), ),
TextFormField( TextFormField(
controller: linkedController, controller: linkedController..text = pgm['linkedin'],
decoration: InputDecoration( //initialValue: pgm['linkedin'],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.red),
hintText: 'Enter a new Linkedin link address'), hintText: 'Enter a new Linkedin link address'),
onChanged: (value) => ln = value, onChanged: (value) => ln = value,
enabled: enb, enabled: enb,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter linkedin link';
}
return null;
},
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -184,35 +281,46 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -184,35 +281,46 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content:FutureBuilder<List<dynamic>>( content:Text('Active Linkedin : '+pgm['linkedin'])
future: getSosmedDesc(), ) ,
);
}, child: const Text('View Active')));
},
),
const SizedBox(
height: 10,
),
FutureBuilder<List<dynamic>>(
future: getTwDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0]; var pgm = snapshot.data[0];
if (snapshot.hasError || if (snapshot.hasError ||
snapshot.data == null || snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) { snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
} }
return Text('Active Linkedin : '+pgm['linkedin']); return listsosmed(
}, const Icon(
),
) ,
);
}, child: Text('View Active'))),
SizedBox(
height: 10,
),
listsosmed(
Icon(
FontAwesomeIcons.twitterSquare, FontAwesomeIcons.twitterSquare,
color: Colors.blueAccent, color: Colors.blueAccent,
), ),
TextFormField( TextFormField(
controller: twitterController, controller: twitterController..text = pgm['twitter'],
decoration: InputDecoration( //initialValue: pgm['twitter'],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.red),
hintText: 'Enter a new Twitter link address'), hintText: 'Enter a new Twitter link address'),
onChanged: (value) => tw = value, onChanged: (value) => tw = value,
enabled: enb, enabled: enb,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter twitter link';
}
return null;
},
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -220,35 +328,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -220,35 +328,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content:FutureBuilder<List<dynamic>>( content:Text('Active Twitter : '+pgm['twitter'])
future: getSosmedDesc(), ) ,
);
}, child: const Text('View Active')));
},
),
const SizedBox(
height: 10,
),
FutureBuilder<List<dynamic>>(
future: getIgDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0]; var pgm = snapshot.data[0];
if (snapshot.hasError || if (snapshot.hasError ||
snapshot.data == null || snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) { snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
} }
return Text('Active Twitter : '+pgm['twitter']); return listsosmed(
}, const Icon(
),
) ,
);
}, child: Text('View Active'))),
SizedBox(
height: 10,
),
listsosmed(
Icon(
FontAwesomeIcons.instagramSquare, FontAwesomeIcons.instagramSquare,
color: Colors.pink, color: Colors.pink,
), ),
TextFormField( TextFormField(
controller: igController, controller: igController..text = pgm['instagram'],
decoration: InputDecoration( // initialValue: pgm['instagram'],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.red),
hintText: 'Enter a new Instagram link address'), hintText: 'Enter a new Instagram link address'),
onChanged: (value) => ig = value, onChanged: (value) => ig = value,
enabled: enb, enabled: enb,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter instagram link';
}
return null;
},
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -256,35 +374,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -256,35 +374,45 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content:FutureBuilder<List<dynamic>>( content:Text('Active Instagram : '+pgm['instagram'])
future: getSosmedDesc(), ) ,
);
}, child: const Text('View Active')));
},
),
const SizedBox(
height: 10,
),
FutureBuilder<List<dynamic>>(
future: getYtDesc(),
builder: (BuildContext context, AsyncSnapshot snapshot) { builder: (BuildContext context, AsyncSnapshot snapshot) {
var pgm = snapshot.data[0]; var pgm = snapshot.data[0];
if (snapshot.hasError || if (snapshot.hasError ||
snapshot.data == null || snapshot.data == null ||
snapshot.connectionState == ConnectionState.waiting) { snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); return const CircularProgressIndicator();
} }
return Text('Active Instagram : '+pgm['instagram']); return listsosmed(
}, const Icon(
),
) ,
);
}, child: Text('View Active'))),
SizedBox(
height: 10,
),
listsosmed(
Icon(
FontAwesomeIcons.youtube, FontAwesomeIcons.youtube,
color: Colors.red, color: Colors.red,
), ),
TextFormField( TextFormField(
controller: youtubeController, controller: youtubeController..text = pgm['youtube'],
decoration: InputDecoration( //initialValue: pgm['youtube'],
decoration: const InputDecoration(
errorStyle: TextStyle(color: Colors.red),
hintText: 'Enter a new Youtube link address'), hintText: 'Enter a new Youtube link address'),
onChanged: (value) => yt = value, onChanged: (value) => yt = value,
enabled: enb, enabled: enb,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter youtube link';
}
return null;
},
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
...@@ -292,21 +420,12 @@ class _SosmedDashboardState extends State<SosmedDashboard> { ...@@ -292,21 +420,12 @@ class _SosmedDashboardState extends State<SosmedDashboard> {
context: context, context: context,
builder: (BuildContext context)=> builder: (BuildContext context)=>
AlertDialog( AlertDialog(
content:FutureBuilder<List<dynamic>>( content:Text('Active Youtube : '+pgm['youtube'])
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: const 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