|
import 'getterSetter.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:provider/provider.dart'; |
|
import 'method.dart'; |
|
|
|
// button untuk menampilkan semua text dari textformfield // |
|
Widget buttonPrintTextFieldValues(GlobalKey<FormState> keys) { |
|
return Consumer<ProviderForTextField>( |
|
builder: (context, crud, _) => FloatingActionButton( |
|
heroTag: 'update gist', |
|
child: Icon(Icons.update), |
|
onPressed: () { |
|
// menyimpan semua value dari textField // |
|
keys.currentState.save(); |
|
crud.listFunctionProvider.forEach((element) { |
|
print(element.str_name); |
|
}); |
|
// get snackbar dari provider dan tampilkan // |
|
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> snackbar = |
|
Scaffold.of(context).showSnackBar(crud.snakbar); |
|
// menampilkan show dialog // |
|
justDialog(crud.listToString, context, snackbar); |
|
}), |
|
); |
|
} |
|
|
|
// widget textformfield atau textfield // |
|
Widget textFormFields({String initialValue, Function onSaved}) { |
|
return Padding( |
|
padding: EdgeInsets.only(bottom: 8), |
|
child: new TextFormField( |
|
initialValue: initialValue, |
|
onSaved: onSaved, |
|
decoration: InputDecoration(border: OutlineInputBorder()), |
|
), |
|
); |
|
} |
|
|
|
// kelas yang beri widget yang memanggil dialog // |
|
class WidgetShowForm { |
|
final GlobalKey<FormState> keys; |
|
final GetASet getter; |
|
final BuildContext context; |
|
WidgetShowForm(this.keys, this.getter, this.context); |
|
|
|
// show dialog untuk input user berapa banyak textfield yang akan di masukkan // |
|
// parameter widget untuk button yang akan mengubah banyak List TextField // |
|
void modalDialogItem(Widget widgets) { |
|
// need context // |
|
AlertDialog alerts = AlertDialog( |
|
shape: RoundedRectangleBorder( |
|
borderRadius: BorderRadius.circular(12.0), |
|
), |
|
titlePadding: EdgeInsets.zero, |
|
content: Container( |
|
height: MediaQuery.of(context).size.height / 3, |
|
width: MediaQuery.of(context).size.width, |
|
child: Column( |
|
children: [ |
|
Form( |
|
key: keys, |
|
child: textFormFields( |
|
initialValue: "1", |
|
onSaved: Valid(getter).saver, |
|
)), |
|
widgets |
|
], |
|
))); |
|
showDialog(context: context, builder: (BuildContext context) => alerts); |
|
} |
|
|
|
// button yang memunculkan dialog "modalDialogItem" . Karena showDialog adalah void, maka harus dipanggil dalam button, // |
|
// contohnya. Dan karena "modalDialogItem" membutuhkan button, buttonUpdateTextFieldCount ditambah ke parameter mehtod. // |
|
// buttonUpdateTextFieldCount akan mengganti banyak LIst<TextField>. Dengan bantuan keys.currentState.save(), nilai dari // |
|
// Function(String) akan di simpan di getterSetter // |
|
Widget showForm() { |
|
return Consumer<ProviderForTextField>( |
|
builder: (context, crud, _) => FloatingActionButton( |
|
onPressed: () => modalDialogItem(buttonUpdateTextFieldCount(() { |
|
// need keys // |
|
keys.currentState.save(); |
|
// need getter setter // |
|
print(getter.str_name); |
|
crud.countTextFieldProvider = int.parse(getter.str_name); |
|
})), |
|
child: Icon(Icons.add), |
|
)); |
|
} |
|
|
|
// button yang membutuhkan VoidCallBack // |
|
Widget buttonUpdateTextFieldCount(VoidCallback voidCallback) { |
|
return FloatingActionButton( |
|
heroTag: 'update gist', |
|
child: Icon(Icons.print), |
|
onPressed: voidCallback); |
|
} |
|
} |
|
|
|
// menampilkan semua hasi imput user di textfield // |
|
void justDialog(String stringToShow, BuildContext context, |
|
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> snackbar) { |
|
// need context // |
|
AlertDialog alerts = AlertDialog( |
|
shape: RoundedRectangleBorder( |
|
borderRadius: BorderRadius.circular(12.0), |
|
), |
|
titlePadding: EdgeInsets.zero, |
|
content: Container( |
|
height: MediaQuery.of(context).size.height / 3, |
|
width: MediaQuery.of(context).size.width, |
|
child: Column( |
|
children: [ |
|
// menampilkan string // |
|
Center(child: Text(stringToShow)), |
|
FlatButton( |
|
onPressed: () { |
|
Navigator.pop(context); |
|
// menutup snakbar setelah 4 detik dialog di tutup // |
|
Future.delayed(Duration(seconds: 4), () { |
|
snackbar.close(); |
|
}); |
|
}, |
|
child: Icon(Icons.close)) |
|
], |
|
))); |
|
showDialog(context: context, builder: (BuildContext context) => alerts); |
|
} |
Jangan lupa tambah plugin provider