text_editor 0.1.3 text_editor: ^0.1.3 copied to clipboard
An Instagram like text editor Flutter widget that helps you to change your text style.
import 'package:flutter/material.dart';
import 'package:text_editor/text_editor.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final fonts = [
'OpenSans',
'Billabong',
'GrandHotel',
'Oswald',
'Quicksand',
];
TextStyle _textStyle = TextStyle(
fontSize: 50,
color: Colors.white,
fontFamily: 'Billabong',
);
String _text = 'Sample Text';
TextAlign _textAlign = TextAlign.center;
void _tapHandler(text, textStyle, textAlign) {
showGeneralDialog(
context: context,
barrierDismissible: false,
transitionDuration: Duration(
milliseconds: 400,
), // how long it takes to popup dialog after button click
pageBuilder: (_, __, ___) {
// your widget implementation
return Container(
color: Colors.black.withOpacity(0.6),
child: Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
// top: false,
child: Container(
child: TextEditor(
fonts: fonts,
text: text,
textStyle: textStyle,
textAlingment: textAlign,
onEditCompleted: (style, align, text) {
setState(() {
_text = text;
_textStyle = style;
_textAlign = align;
});
Navigator.pop(context);
},
),
),
),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: SafeArea(
top: false,
child: Center(
child: Stack(
children: [
Image.asset('assets/story.png'),
Center(
child: GestureDetector(
onTap: () => _tapHandler(_text, _textStyle, _textAlign),
child: Text(
_text,
style: _textStyle,
textAlign: _textAlign,
),
),
),
],
),
),
),
);
}
}