Last active
March 20, 2021 14:50
-
-
Save shalithasuranga/7d3625df063fd0bf7d105804869a07f7 to your computer and use it in GitHub Desktop.
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 'dart:io'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
final textController = new TextEditingController(); | |
final globalKey = GlobalKey<ScaffoldState>(); | |
final String fileName = 'textPadNote.txt'; | |
Future<void> _exportToFile(BuildContext context) async { | |
final File file = File('${Directory.current.absolute.path}/${fileName}'); | |
final snackBar = SnackBar(content: Text('Saved to: ${file.path}')); | |
await file.writeAsString(textController.text); | |
globalKey.currentState.showSnackBar(snackBar); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'TextPad', | |
theme: ThemeData( | |
brightness: Brightness.dark, | |
), | |
home: Scaffold( | |
key: globalKey, | |
appBar: AppBar( | |
title: Text('TextPad'), | |
actions: <Widget>[ | |
IconButton( | |
icon: const Icon(Icons.save), | |
tooltip: 'Export to ${fileName}', | |
onPressed: () {_exportToFile(context);} | |
)] | |
), | |
body: Center( | |
child: TextField( | |
controller: textController, | |
maxLines: null, | |
keyboardType: TextInputType.multiline, | |
expands: true, | |
decoration: InputDecoration( | |
hintText: 'Play with your notes here...', | |
contentPadding: EdgeInsets.all(12.0) | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment