Last active
February 23, 2024 06:44
-
-
Save sawin0/8262f087524ce9b1a22d192422bddd37 to your computer and use it in GitHub Desktop.
reading rtf file using Dart and Flutter. Answer to this question: https://stackoverflow.com/questions/78045540/how-to-read-and-write-rtf-file-in-flutter-app/78045582#78045582
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() { | |
debugInvertOversizedImages = true; | |
runApp(const MaterialApp(home: RftReaderScreen())); | |
} | |
class RftReaderScreen extends StatefulWidget { | |
const RftReaderScreen({Key? key}) : super(key: key); | |
@override | |
State<RftReaderScreen> createState() => _RftReaderScreenState(); | |
} | |
class _RftReaderScreenState extends State<RftReaderScreen> { | |
String? _res; | |
@override | |
void initState() { | |
super.initState(); | |
// Here we are accessing example.rtf file | |
// loadString method fetches all the text from example.rtf file | |
// after loading all the text we are setting to our local variable | |
rootBundle.loadString("assets/example.rtf").then((value) => setState(() { | |
_res = value; | |
})); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Text(_res ?? "Loading . . ."), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment