Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Created March 19, 2023 22:17
Show Gist options
  • Save DaisukeNagata/6d24a166d4edf9e4949c65515422ca91 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/6d24a166d4edf9e4949c65515422ca91 to your computer and use it in GitHub Desktop.
Techniques for putting the cursor at the end of text
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _animationText = '';
final String _animationTextList =
'''# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.''';
@override
void initState() {
super.initState();
_updateMsg();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 20),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: RichText(
text: TextSpan(
text: _animationText,
style: const TextStyle(color: Colors.black),
children: [
WidgetSpan(
child: SizedBox(
width: 10,
height: 20,
child: Image.asset(
'assets/sample.webp',
fit: BoxFit.fill,
),
),
),
],
),
),
),
);
}
Future<void> _updateMsg() async {
for (var i = 0; i < _animationTextList.length; i++) {
// ignore: use_string_buffers
setState(() {
_animationText += _animationTextList.substring(i, i + 1);
});
await Future.delayed(const Duration(milliseconds: 200), () {
const Duration(milliseconds: 200);
});
}
}
}
@DaisukeNagata
Copy link
Author

2023-03-20.7.15.30.mov

@DaisukeNagata
Copy link
Author

Set the image path to pubspec.ymal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment