added prj editing page, must change to dialog bcz page too big
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import "package:prod/views/editors.dart";
|
||||
import "package:prod/views/home.dart";
|
||||
import "package:prod/views/managePrj.dart";
|
||||
import "package:yaru/yaru.dart";
|
||||
import "package:provider/provider.dart";
|
||||
import "package:prod/models/globalModel.dart";
|
||||
@@ -27,6 +28,7 @@ class MyApp extends StatelessWidget {
|
||||
routes: {
|
||||
"/": (context) => HomePage(),
|
||||
"/editors": (context) => EditorEditor(),
|
||||
"/manageprj": (context) => ManageProject(),
|
||||
},
|
||||
initialRoute: "/",
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ class Editor {
|
||||
final String name;
|
||||
final String command;
|
||||
final String commandTemplate;
|
||||
// final Icon icon;
|
||||
|
||||
const Editor(
|
||||
this.sname,
|
||||
@@ -39,6 +38,7 @@ class Editor {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"sname": sname,
|
||||
"name": name,
|
||||
"command": command,
|
||||
"commandTemplate": commandTemplate,
|
||||
@@ -50,7 +50,8 @@ class Editor {
|
||||
if (!data.containsKey("name") ||
|
||||
!data.containsKey("command") ||
|
||||
!data.containsKey("commandTemplate") ||
|
||||
!data.containsKey("id")) {
|
||||
!data.containsKey("id") ||
|
||||
!data.containsKey("sname")) {
|
||||
print("Found invalid editor config when parsing: $data");
|
||||
return Editor("!!", "null", "null", "null", "null");
|
||||
}
|
||||
|
||||
@@ -12,11 +12,24 @@ class GlobalModel extends ChangeNotifier {
|
||||
late List<Editor> editors;
|
||||
late SharedPreferences prefs;
|
||||
bool importedData = false;
|
||||
bool edited = false;
|
||||
|
||||
GlobalModel() {
|
||||
SharedPreferences.getInstance().then((a) {
|
||||
print("Loaded sp");
|
||||
prefs = a;
|
||||
if (prefs.containsKey(kEditorsKey)) {
|
||||
String edtData = prefs.getString(kEditorsKey)!;
|
||||
List<dynamic> data = jsonDecode(edtData);
|
||||
editors = [];
|
||||
for (var d in data) {
|
||||
editors.add(Editor.fromJson(d));
|
||||
}
|
||||
} else {
|
||||
editors = [];
|
||||
prefs.setString(kEditorsKey, jsonEncode(editors));
|
||||
}
|
||||
|
||||
if (prefs.containsKey(kProjectsKey)) {
|
||||
String prjData = prefs.getString(kProjectsKey)!;
|
||||
List<dynamic> data = jsonDecode(prjData);
|
||||
@@ -30,18 +43,6 @@ class GlobalModel extends ChangeNotifier {
|
||||
}
|
||||
print(projects);
|
||||
|
||||
if (prefs.containsKey(kEditorsKey)) {
|
||||
String edtData = prefs.getString(kEditorsKey)!;
|
||||
List<dynamic> data = jsonDecode(edtData);
|
||||
editors = [];
|
||||
for (var d in data) {
|
||||
editors.add(Editor.fromJson(d));
|
||||
}
|
||||
} else {
|
||||
editors = [];
|
||||
prefs.setString(kEditorsKey, jsonEncode(editors));
|
||||
}
|
||||
|
||||
hoverShow = List.filled(projects.length, false, growable: true);
|
||||
print("loaded data");
|
||||
importedData = true;
|
||||
@@ -94,6 +95,11 @@ class GlobalModel extends ChangeNotifier {
|
||||
return hoverShow[index];
|
||||
}
|
||||
|
||||
void updatePrj(int index, Project prj) {
|
||||
projects[index] = prj;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Editor List Management.
|
||||
|
||||
void addEdt(Editor edt) {
|
||||
@@ -115,4 +121,15 @@ class GlobalModel extends ChangeNotifier {
|
||||
Editor nthEdt(int index) {
|
||||
return editors[index];
|
||||
}
|
||||
|
||||
// Editing controller
|
||||
|
||||
bool get isEdited {
|
||||
return edited;
|
||||
}
|
||||
|
||||
void updateEdited(bool a) {
|
||||
edited = a;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class HomePage extends StatelessWidget {
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: !gm.importedData
|
||||
? Container()
|
||||
? YaruLinearProgressIndicator()
|
||||
: gm.lenPrj > 0
|
||||
? LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
|
||||
141
lib/views/managePrj.dart
Normal file
141
lib/views/managePrj.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:flutter/material.dart";
|
||||
import "package:prod/models/globalModel.dart";
|
||||
import "package:prod/models/project.dart";
|
||||
import "package:provider/provider.dart";
|
||||
|
||||
class ManageProject extends StatelessWidget {
|
||||
const ManageProject({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final id = ModalRoute.of(context)?.settings.arguments as int;
|
||||
GlobalModel gm = Provider.of(context);
|
||||
final Project prj = gm.nthPrj(id);
|
||||
TextEditingController nameController = TextEditingController();
|
||||
TextEditingController pathController = TextEditingController();
|
||||
TextEditingController langController = TextEditingController();
|
||||
nameController.text = prj.name;
|
||||
pathController.text = prj.path.path;
|
||||
langController.text = prj.language;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("/ PROject Dashboard / Editing ${prj.name} ")),
|
||||
body: Container(
|
||||
// constraints: BoxConstraints(maxWidth: 500),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
// title: gm.isEdited ? Text("Unsaved Changes") : null,
|
||||
pinned: false,
|
||||
snap: false,
|
||||
floating: false,
|
||||
automaticallyImplyLeading: false,
|
||||
automaticallyImplyActions: false,
|
||||
backgroundColor: Colors.transparent,
|
||||
shape: LinearBorder(),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: TextField(
|
||||
style: TextStyle(fontSize: 50),
|
||||
controller: nameController,
|
||||
textAlign: .center,
|
||||
// onEditingComplete: () => gm.updateEdited(true),
|
||||
decoration: InputDecoration(
|
||||
border: .none,
|
||||
enabledBorder: .none,
|
||||
fillColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
style: TextStyle(fontSize: 30),
|
||||
controller: pathController,
|
||||
textAlign: .center,
|
||||
// onEditingComplete: () => gm.updateEdited(true),
|
||||
decoration: InputDecoration(
|
||||
border: .none,
|
||||
// enabledBorder: .none,
|
||||
fillColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: TextField(
|
||||
style: TextStyle(fontSize: 30),
|
||||
controller: langController,
|
||||
textAlign: .center,
|
||||
// onEditingComplete: () => gm.updateEdited(true),
|
||||
decoration: InputDecoration(
|
||||
border: .none,
|
||||
enabledBorder: .none,
|
||||
fillColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SliverList.list(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
OutlinedButton(
|
||||
child: Text("Delete"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
gm.delPrj(id);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Deleted ${prj.name}"),
|
||||
duration: Duration(milliseconds: 2350),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
OutlinedButton(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
OutlinedButton(
|
||||
child: Text("Save"),
|
||||
onPressed: () {
|
||||
gm.updatePrj(
|
||||
id,
|
||||
Project(
|
||||
nameController.text,
|
||||
langController.text,
|
||||
File(pathController.text),
|
||||
prj.editors,
|
||||
prj.isGit,
|
||||
prj.enableTerminal,
|
||||
),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Updated Project Details"),
|
||||
duration: Duration(milliseconds: 2500),
|
||||
),
|
||||
);
|
||||
},
|
||||
// gm.updateEdited(false);
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// SliverList.builder(
|
||||
// itemCount: 3,
|
||||
// itemBuilder: (context, index) {
|
||||
// return Placeholder();
|
||||
// },
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,6 @@ class EditorCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
GlobalModel gm = Provider.of<GlobalModel>(context);
|
||||
final Editor edt = gm.nthEdt(id);
|
||||
final String icon =
|
||||
"${edt.name.substring(0, 1).toUpperCase()}${edt.name.substring(1, 2).toLowerCase()}";
|
||||
return YaruBanner(
|
||||
padding: .only(
|
||||
left: kYaruPagePadding,
|
||||
@@ -28,7 +26,7 @@ class EditorCard extends StatelessWidget {
|
||||
|
||||
child: Row(
|
||||
children: [
|
||||
Text("$icon", style: TextStyle(fontSize: 50)),
|
||||
Text("${edt.sname}", style: TextStyle(fontSize: 50)),
|
||||
VerticalDivider(width: 20, thickness: 2),
|
||||
Flexible(
|
||||
child: Column(
|
||||
|
||||
@@ -10,6 +10,7 @@ class ProjFAB extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
TextEditingController nameController = TextEditingController();
|
||||
TextEditingController locationController = TextEditingController();
|
||||
TextEditingController languageController = TextEditingController();
|
||||
return FloatingActionButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
@@ -33,6 +34,13 @@ class ProjFAB extends StatelessWidget {
|
||||
decoration: InputDecoration(labelText: "Path"),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextField(
|
||||
controller: languageController,
|
||||
decoration: InputDecoration(labelText: "Language"),
|
||||
),
|
||||
),
|
||||
|
||||
Row(
|
||||
mainAxisAlignment: .end,
|
||||
@@ -47,7 +55,7 @@ class ProjFAB extends StatelessWidget {
|
||||
Provider.of<GlobalModel>(context, listen: false).addPrj(
|
||||
Project.newValidated(
|
||||
nameController.text,
|
||||
"Rust",
|
||||
languageController.text,
|
||||
locationController.text,
|
||||
[],
|
||||
true,
|
||||
|
||||
@@ -23,10 +23,14 @@ class ProjectCard extends StatelessWidget {
|
||||
),
|
||||
onHover: (st) => gm.setHoverShow(id, st),
|
||||
onTap: () {
|
||||
var shell = Shell();
|
||||
Editor edt1 = gm.editors[0];
|
||||
String comm = edt1.commandTemplate.replaceAll("\$path", prj.path.path);
|
||||
shell.run(comm);
|
||||
// var shell = Shell();
|
||||
// Editor edt1 = gm.editors[0];
|
||||
// String comm = edt1.commandTemplate.replaceAll("\$path", prj.path.path);
|
||||
// shell.run(comm);
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(content: Text("Launched "), duration: Duration(seconds: 3)),
|
||||
// );
|
||||
Navigator.pushNamed(context, "/manageprj", arguments: id);
|
||||
},
|
||||
child: Center(
|
||||
child: Column(
|
||||
@@ -46,15 +50,15 @@ class ProjectCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
gm.getHoverShow(id) ? Text("${prj.path.path}") : Container(),
|
||||
gm.getHoverShow(id)
|
||||
? IconButton(
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: () => gm.delPrj(id),
|
||||
style: IconButton.styleFrom(
|
||||
overlayColor: Color(0xffff0000),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
// gm.getHoverShow(id)
|
||||
// ? IconButton(
|
||||
// icon: Icon(Icons.close),
|
||||
// onPressed: () => gm.delPrj(id),
|
||||
// style: IconButton.styleFrom(
|
||||
// overlayColor: Color(0xffff0000),
|
||||
// ),
|
||||
// )
|
||||
// : Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user