Skip to content

Instantly share code, notes, and snippets.

@dhruvilp
Created January 30, 2021 18:58
Show Gist options
  • Select an option

  • Save dhruvilp/61081f0a53abee37d16cef3bedcd2524 to your computer and use it in GitHub Desktop.

Select an option

Save dhruvilp/61081f0a53abee37d16cef3bedcd2524 to your computer and use it in GitHub Desktop.
Flutter Editable Button Text
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Editable Button Text Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Editable Button Text Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _controller;
@override
void initState() {
super.initState();
_controller = TextEditingController.fromValue(
TextEditingValue(text: 'REPLACE ME'),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey.shade900,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 18.0),
child: Text(
'Editable Button',
style: Theme.of(context).textTheme.headline6,
),
),
Container(
width: 250.0,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.blueAccent[400]),
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.all(25.0)),
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0))),
),
onPressed: () {},
child: EditableText(
controller: _controller,
backgroundCursorColor: Colors.amber,
cursorColor: Colors.white,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 18.0,
),
focusNode: FocusNode(debugLabel: 'kEditableTextWidget'),
textAlign: TextAlign.center,
textCapitalization: TextCapitalization.characters,
selectionColor: Colors.grey.shade700,
),
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment