Skip to content

Instantly share code, notes, and snippets.

@mihalycsaba
Created January 23, 2023 12:28
Show Gist options
  • Save mihalycsaba/b7d5af786b890614ec049240a5857d72 to your computer and use it in GitHub Desktop.
Save mihalycsaba/b7d5af786b890614ec049240a5857d72 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
final TextStyle _style = const TextStyle(fontSize: 15);
late TextEditingController _controller;
@override
void initState() {
super.initState();
_controller = TextEditingController();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
SizedBox(
width: 30,
height: double.infinity,
child: ListView.builder(
itemCount: '\n'.allMatches(_controller.toString()).length + 1,
itemBuilder: (BuildContext context, int index) {
return Text('${index + 1}.', style: _style,);
},
),
),
Expanded(
child: Container(
padding: const EdgeInsets.only(top:5),
alignment: Alignment.topLeft,
child: TextField(
decoration: const InputDecoration.collapsed(hintText: 'Text'),
style: _style,
keyboardType: TextInputType.multiline,
maxLines: null,
controller: _controller,
onChanged: (value) => setState(() {}),
),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment