Skip to content

Instantly share code, notes, and snippets.

@pkozlovskiy
Last active May 19, 2020 19:24
Show Gist options
  • Save pkozlovskiy/b1b3456769674ec6ab83932bd53c69da to your computer and use it in GitHub Desktop.
Save pkozlovskiy/b1b3456769674ec6ab83932bd53c69da to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
var _discountController = new TextEditingController();
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: ClearableTextFormField(
controller: _discountController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
icon: Icon(Icons.money_off),
floatingLabelBehavior: FloatingLabelBehavior.auto,
labelText: 'Скидка'),
),
),
),
);
}
}
class ClearableTextFormField extends TextFormField {
ClearableTextFormField({
TextEditingController controller,
FormFieldValidator validator,
TextInputType keyboardType,
InputDecoration decoration,
}) : super(
validator: validator,
controller: controller,
keyboardType: keyboardType,
decoration: InputDecoration(
icon: decoration.icon,
labelText: decoration.labelText,
floatingLabelBehavior: FloatingLabelBehavior.auto,
suffixIcon: ValueListenableBuilder(
valueListenable: controller,
builder: (context, value, child) => Visibility(
visible: value.text.isNotEmpty,
child: IconButton(
icon: Icon(Icons.close),
onPressed: () => controller.clear(),
),
),
)),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment