Commit 3e6d6da2 authored by Dio Maulana's avatar Dio Maulana

mempersimple codingan

parent caea547d
...@@ -12,66 +12,60 @@ class GeneralSetting extends StatefulWidget { ...@@ -12,66 +12,60 @@ class GeneralSetting extends StatefulWidget {
class _GeneralSettingState extends State<GeneralSetting> { class _GeneralSettingState extends State<GeneralSetting> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool? isOrderActive = prefs.getBool('isOrderActive'); final bool isOrderActive = prefs.getBool('isOrderActive') ?? true;
final bool? isAdActive = prefs.getBool('isAdActive'); final bool isAdActive = prefs.getBool('isAdActive') ?? true;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("General Setting"), title: const Text("General Setting"),
backgroundColor: backgroundAppBar, backgroundColor: backgroundAppBar,
), ),
body: Column( body: SizedBox(
height: MediaQuery.of(context).size.height,
child: ListView(
children: [ children: [
Container( titleHeader(context, "General"),
color: Colors.black.withOpacity(0.5), listWithSwitch(isOrderActive, "Tampilkan Order", "isOrderActive"),
height: 50, listWithSwitch(isAdActive, "Tampilkan Iklan", "isAdActive"),
width: MediaQuery.of(context).size.width * 1,
child: Container(
margin: EdgeInsets.only(left: 10),
child: const Align(
alignment: Alignment.centerLeft, child: Text("General")),
),
),
Container(
margin: const EdgeInsets.only(left: 10, right: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Tampilkan Order",
style: TextStyle(
fontSize: MediaQuery.of(context).size.height * 0.025,
fontWeight: FontWeight.w500),
),
Switch(
value: (isOrderActive == null) ? true : isOrderActive,
onChanged: (bool newValue) async {
await prefs.setBool('isOrderActive', newValue);
setState(() {});
})
], ],
), ),
), ),
Container( );
margin: const EdgeInsets.only(left: 10, right: 10), }
Container listWithSwitch(bool isOrderActive, String title, String prefName) {
return Container(
margin: const EdgeInsets.only(left: 10, right: 10, top: 15),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Tampilkan Iklan", title,
style: TextStyle( style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
fontSize: MediaQuery.of(context).size.height * 0.025,
fontWeight: FontWeight.w500),
), ),
Switch( Switch(
value: (isAdActive == null) ? true : isAdActive, value: isOrderActive,
onChanged: (bool newValue) async { onChanged: (bool newValue) async {
await prefs.setBool('isAdActive', newValue); await prefs.setBool(prefName, newValue);
setState(() {}); setState(() {});
}) })
], ],
), ),
) );
], }
Container titleHeader(BuildContext context, String title) {
return Container(
color: Colors.black.withOpacity(0.5),
height: 50,
width: MediaQuery.of(context).size.width * 1,
child: Container(
margin: const EdgeInsets.only(left: 10),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
title,
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 20),
)),
), ),
); );
} }
......
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