Skip to content

Commit

Permalink
removed File_picker dep/references doesnt seem to work on android 15.…
Browse files Browse the repository at this point in the history
… set static save location and name till I can find a better method that works
  • Loading branch information
deathblade666 committed Aug 30, 2024
1 parent 5e77632 commit 2e737ac
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<application
android:label="mdeditor"
android:name="${applicationName}"
Expand Down
48 changes: 25 additions & 23 deletions lib/pages/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import 'package:shared_preferences/shared_preferences.dart';
enableWorkCount,
}

//TODO: Implement new functions
// function for theme control

String filePath = '';
String _filename = '';
bool fullEdit = true;
Expand All @@ -32,7 +29,7 @@ class Menu extends StatefulWidget {
Menu(
this.prefs,
this.inputText,
this.OpenFile,
this.openFile,
this.wordCount,
{required this.onEnableWordCount,
required this.onModeToggle,
Expand All @@ -47,21 +44,21 @@ class Menu extends StatefulWidget {
final void Function(bool fullEdit) onModeToggle;
final void Function(bool WordCount) onEnableWordCount;
void Function(String? selectedTheme) onThemeSelected;
TextEditingController OpenFile = TextEditingController();
TextEditingController openFile = TextEditingController();
final String inputText;
int wordCount;
SharedPreferences prefs;


@override
State<Menu> createState() => MenuState(inputText, OpenFile, wordCount, prefs);
State<Menu> createState() => MenuState(inputText, openFile, wordCount, prefs);
}
class MenuState extends State<Menu> {
//Declarations
MenuState(this.inputText, this.OpenFile, this.wordCount,this.prefs);
MenuState(this.inputText, this.openFile, this.wordCount,this.prefs);
final String inputText;
int wordCount=0;
TextEditingController OpenFile = TextEditingController();
TextEditingController openFile = TextEditingController();
bool switchModeValue = false;
bool switchWCValue = false;
SharedPreferences prefs;
Expand All @@ -71,7 +68,7 @@ class Menu extends StatefulWidget {
prefs.reload();
bool? RetainInputSwitch = prefs.getBool('RetainInputSwitch');
if (RetainInputSwitch == true){
prefs.setString("InputText", OpenFile.text);
prefs.setString("InputText", openFile.text);
}
if (RetainInputSwitch == false){
await prefs.remove('InputText');
Expand Down Expand Up @@ -108,26 +105,31 @@ class Menu extends StatefulWidget {
PopupMenuItem<menuItems>(
value: menuItems.save,
onTap: () async {
//List<int> list = utf8.encode(OpenFile.text);
Uint8List bytes = utf8.encode(OpenFile.text);
//Uint8List.fromList(list);
final outputfile = await FileSaver.instance.saveAs(
ext: "md",
name: "test",
//file: file,
bytes: bytes,
mimeType: MimeType.custom,
customMimeType: 'text/markdown',
);
final file = File(outputfile!);
file.writeAsString(OpenFile.text);
List<int> list = utf8.encode(openFile.text);
//Uint8List bytes = utf8.encode(openFile.text);
Uint8List bytes = Uint8List.fromList(list);
var file = File('/sdcard/mdeditor/test files/test58.md');
//final outputfile = await FileSaver.instance.saveAs(
// ext: "md",
//name: "test58",
// file: file,
// mimeType: MimeType.custom,
// customMimeType: 'text/markdown',
// );

//var file = File(outputfile!);
var sink = file.openWrite();
sink.add(bytes);
//sink.write(openFile.text);
//file.writeAsString(openFile.text);


showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: const Text("Success"),
content: Text("Save successfully to $outputfile"),
content: Text("Save successfully to "),
);
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:markdown_editor_plus/widgets/markdown_parse.dart';

// ignore: must_be_immutable
class Renderer extends StatelessWidget {
Renderer(this.OpenFile,this.value,{super.key});
Renderer(this.openFile,this.value,{super.key});
String value;
TextEditingController OpenFile = TextEditingController();
TextEditingController openFile = TextEditingController();
ScrollController autoScroll = ScrollController();

@override
Expand Down
10 changes: 5 additions & 5 deletions lib/pages/split_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class editorState extends State<Editor> {
bool showWordCount = WordCount;
int wordCount = 0;
var theme = ThemeMode.system;
TextEditingController OpenFile = TextEditingController();
TextEditingController openFile = TextEditingController();

@override
void initState() {
Expand Down Expand Up @@ -60,7 +60,7 @@ class editorState extends State<Editor> {
void loadedFile(fileContent){
setState(() {
var regExp = RegExp(r"\w+(\'\w+)?");
OpenFile.text = fileContent;
openFile.text = fileContent;
contents = fileContent;
wordCount = regExp.allMatches(contents).length;
});
Expand Down Expand Up @@ -103,11 +103,11 @@ class editorState extends State<Editor> {
visible: _full,
child:Expanded(
flex: 2,
child: Renderer(OpenFile, contents),
child: Renderer(openFile, contents),
),
),
Expanded(
child: mdtextfield(OpenFile, fileContent,ontextchanged: mdText,),
child: mdtextfield(openFile, fileContent,ontextchanged: mdText,),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand All @@ -128,7 +128,7 @@ class editorState extends State<Editor> {
prefs,
onFileLoad: loadedFile,
contents,
OpenFile,
openFile,
onfileName: setFileName,
onModeToggle: switchViewMode,
wordCount, onEnableWordCount: enableWordCount,
Expand Down
12 changes: 6 additions & 6 deletions lib/pages/textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import 'package:markdown_editor_plus/markdown_editor_plus.dart';
// ignore: must_be_immutable
class mdtextfield extends StatefulWidget {
mdtextfield(
this.OpenFile,
this.openFile,
this.fileContent,
{required this.ontextchanged,
super.key
}
);
final void Function(String contents) ontextchanged;
TextEditingController OpenFile;
TextEditingController openFile;
String fileContent;

@override
State<mdtextfield> createState() => mdtextfieldState(OpenFile,fileContent);
State<mdtextfield> createState() => mdtextfieldState(openFile,fileContent);
}

// ignore: camel_case_types
class mdtextfieldState extends State<mdtextfield> {
mdtextfieldState(this.OpenFile, this.fileContent);
mdtextfieldState(this.openFile, this.fileContent);
String fileContent;
TextEditingController OpenFile = TextEditingController();
TextEditingController openFile = TextEditingController();


// ignore: avoid_types_as_parameter_names, non_constant_identifier_names
Expand Down Expand Up @@ -53,7 +53,7 @@ class mdtextfieldState extends State<mdtextfield> {
expands: true,
emojiConvert: true,
maxLines: null,
controller: OpenFile,
controller: openFile,
cursorColor: Theme.of(context).colorScheme.primary,

),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
shared_preferences: ^2.3.2
file_picker: ^8.1.2
file_saver: ^0.2.14
markdown_editor_plus: ^0.2.15
dynamic_color: 1.6.9
file_picker: ^8.1.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 2e737ac

Please sign in to comment.