-
buat model
-
buat function
-
buat widget
-
buat home
Created
June 28, 2020 16:15
-
-
Save manofi21/f1bf3b14f8ac8ae45e15d8050e4eba3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cobalah/model.dart'; | |
class Valid{ | |
/*contructor untuk meminta "object" getter setter yang sama*/ | |
GetASet parts; | |
Valid(this.parts); | |
Function saver(String auto) { | |
parts.str_name = auto; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'function.dart'; | |
import 'model.dart'; | |
import 'widgets.dart'; | |
class Homes extends StatefulWidget { | |
@override | |
_HomesState createState() => _HomesState(); | |
} | |
/* buat object mengakses getter setter */ | |
GetASet parts = new GetASet(); | |
/* buat object mengakses widget dan menasukkan contructor getter setter */ | |
Widgets wrap = Widgets(parts); | |
/* lakukan hal yang sama */ | |
Valid val = new Valid(parts); | |
class _HomesState extends State<Homes> { | |
final globalk = new GlobalKey<FormState>(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
child: wrap.layout( | |
globalKey: globalk, | |
theWidgets: [ | |
wrap.field(val.saver), | |
wrap.button(globalk) | |
] | |
)), | |
); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*kelas getter setter*/ | |
class GetASet{ | |
String str; | |
String get str_name{ | |
return str; | |
} | |
void set str_name(String name){ | |
this.str = name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'model.dart'; | |
/* menambah contructor getter setter */ | |
class Widgets { | |
GetASet parts; | |
Widgets(this.parts); | |
/* button widget untuk meyimpan input user dengan GlobalKey */ | |
Widget button(GlobalKey<FormState> keys) { | |
return RaisedButton( | |
child: Text("press"), | |
onPressed: () { | |
/*fatal : karena tanpa syntax ini, input user tidak di simpan*/ | |
keys.currentState.save(); | |
}); | |
} | |
// widget textfield untuk menempatkan function | |
Widget field(Function saver) { | |
return TextFormField( | |
onSaved: saver, | |
); | |
} | |
/* Form widget untuk menaruh key dan menempatkan semua widget ada pada satu tree/akses dalam key yang sama */ | |
Widget layout({GlobalKey<FormState> globalKey, List<Widget> theWidgets}) { | |
return Form( | |
/*key yang akan menyimpan input user*/ | |
key: globalKey, | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
mainAxisSize: MainAxisSize.max, | |
/*widget yang akan disusun agar menadapat satu key yang sama*/ | |
children: theWidgets), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment