Files
flutter-todos/lib/widgets/edit_dialog.dart
2019-07-25 18:12:09 +08:00

61 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:todo_list/i10n/localization_intl.dart';
class EditDialog extends StatelessWidget {
final VoidCallback onSure;
final String title;
final String hintText;
final String initialValue;
final ValueChanged<String> onValueChanged;
final TextStyle cancelTextStyle;
final TextStyle sureTextStyle;
const EditDialog({
Key key,
this.onSure,
this.title,
this.hintText,
this.initialValue, this.onValueChanged, this.cancelTextStyle, this.sureTextStyle,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(title ?? ""),
content: Form(
autovalidate: true,
child: TextFormField(
initialValue: initialValue ?? "",
validator: (text){
if(onValueChanged != null)
onValueChanged(text);
},
decoration: InputDecoration(
hintText: hintText ?? "",
),
),
),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
DemoLocalizations.of(context).cancel,
style:cancelTextStyle ?? TextStyle(color: Colors.redAccent),
),
),
FlatButton(
onPressed: (){
if(onSure != null) onSure();
Navigator.pop(context);
},
child: Text(DemoLocalizations.of(context).ok,
style:sureTextStyle ?? TextStyle(color: Colors.black)),
),
],
);
}
}