Open Files / Create New File
This commit is contained in:
parent
cdbe4d8c9b
commit
6aac11934f
|
@ -13,6 +13,7 @@ class Editor extends StatefulWidget {
|
|||
class _Editor extends State<Editor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return InputListener(LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
|
||||
//print("opening document " + path + " " + startLine.toString());
|
||||
return View();
|
||||
|
|
|
@ -8,9 +8,9 @@ import 'outline.dart';
|
|||
|
||||
void main(List<String> args) {
|
||||
var docfile = LineFile();
|
||||
//if (args.length > 1) {
|
||||
docfile.openFile("./example.md", 0);
|
||||
//}
|
||||
if (args.length > 0) {
|
||||
docfile.openFile(args[0], 0);
|
||||
}
|
||||
var doc = ChangeNotifierProvider.value(value: docfile);
|
||||
|
||||
runApp(MultiProvider(
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
import 'package:subwrite/theme.dart';
|
||||
import 'file.dart';
|
||||
import 'line_info.dart';
|
||||
|
||||
|
@ -34,18 +38,70 @@ class _View extends State<View> with SingleTickerProviderStateMixin {
|
|||
Widget build(BuildContext context) {
|
||||
LineFile doc = Provider.of<LineFile>(context);
|
||||
|
||||
return ScrollablePositionedList.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemScrollController: doc.scrollController,
|
||||
itemCount: doc.lines(),
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (BuildContext bcontext, int index) {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: doc.backingLines[index],
|
||||
builder: (lcontext, lineinfo) {
|
||||
return Provider.of<LineInfo>(lcontext).build(context,_animationController);
|
||||
});
|
||||
});
|
||||
if (doc.backingLines.isEmpty) {
|
||||
return Center(
|
||||
child: Row (
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
|
||||
ElevatedButton.icon(onPressed: () async {
|
||||
String? result = await FilePicker.platform.saveFile(
|
||||
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
File(result).createSync(recursive: false);
|
||||
doc.openFile(result, 0);
|
||||
doc.focus.requestFocus();
|
||||
} else {
|
||||
// User canceled the picker
|
||||
}
|
||||
|
||||
|
||||
}, icon: Icon(Icons.create, color: foreground), label: const Text("New Document"),
|
||||
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs),
|
||||
foregroundColor: MaterialStateProperty.all(foreground))),
|
||||
|
||||
SizedBox(width: 20,),
|
||||
|
||||
ElevatedButton.icon(onPressed: () async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
allowMultiple: false,
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['md','txt'],
|
||||
);
|
||||
if (result != null) {
|
||||
doc.openFile(result.files.single.path!, 0);
|
||||
} else {
|
||||
// User canceled the picker
|
||||
}
|
||||
|
||||
|
||||
}, icon: Icon(Icons.file_open, color: foreground), label: const Text("Open Document"),
|
||||
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs),
|
||||
foregroundColor: MaterialStateProperty.all(foreground))),
|
||||
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
} else {
|
||||
return ScrollablePositionedList.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemScrollController: doc.scrollController,
|
||||
itemCount: doc.lines(),
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (BuildContext bcontext, int index) {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: doc.backingLines[index],
|
||||
builder: (lcontext, lineinfo) {
|
||||
return Provider.of<LineInfo>(lcontext).build(
|
||||
context, _animationController);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ project(runner LANGUAGES CXX)
|
|||
|
||||
# The name of the executable created for the application. Change this to change
|
||||
# the on-disk name of your application.
|
||||
set(BINARY_NAME "sarahdown")
|
||||
set(BINARY_NAME "subwrite")
|
||||
# The unique GTK application identifier for this application. See:
|
||||
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
|
||||
set(APPLICATION_ID "com.example.sarahdown")
|
||||
set(APPLICATION_ID "tech.resistant.subwrite")
|
||||
|
||||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||||
# versions of CMake.
|
||||
|
|
47
pubspec.lock
47
pubspec.lock
|
@ -50,6 +50,20 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
file_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.2.0+1"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -62,11 +76,30 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.4"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -109,6 +142,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.2"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -177,6 +217,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
sdks:
|
||||
dart: ">=2.18.0 <3.0.0"
|
||||
flutter: ">=2.12.0"
|
||||
|
|
|
@ -38,6 +38,7 @@ dependencies:
|
|||
cupertino_icons: ^1.0.2
|
||||
provider: ^6.0.2
|
||||
scrollable_positioned_list: ^0.3.2
|
||||
file_picker: 5.2.0+1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue