Skip to content

phui backend #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions lib/widgets/category_picker.dart

This file was deleted.

50 changes: 50 additions & 0 deletions lib/widgets/layout_picker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:pheno_ui/interface/strapi.dart';
import 'package:pheno_ui_tester/widgets/picker_state.dart';

import 'render_layout.dart';

class LayoutPicker extends PickerWidget {
@override
get getList => _getList;

@override
get builder => _builder;

@override
get title => entry != null ? entry!.path : 'Category';

final PickerEntry? entry;

const LayoutPicker({ super.key, this.entry });

Widget _builder(PickerEntry entry, BuildContext context, _) {
if (entry.type == PickerEntryType.tag) {
return LayoutPicker(entry: entry);
}
return RenderLayout(
tagId: this.entry!.id,
initialRoute: entry.name,
);
}

Future<List<PickerEntry>> _getList() async {
List<PickerEntry> entries = [];
final tagList = await Strapi().getCategoryList(entry?.id);
for (var tagEntry in tagList) {
entries.add(PickerEntry(tagEntry, PickerEntryType.tag));
}

if (entry != null) {
final layoutList = await Strapi().getScreenList(entry!.id);
for (var layoutEntry in layoutList) {
entries.add(PickerEntry(layoutEntry, PickerEntryType.layout));
}
}

return entries;
}

@override
State<LayoutPicker> createState() => PickerState();
}
4 changes: 2 additions & 2 deletions lib/widgets/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:pheno_ui/interface/strapi.dart';
import 'package:pheno_ui_tester/widgets/loading_screen.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'category_picker.dart';
import 'layout_picker.dart';

class Login extends StatefulWidget {
const Login({super.key});
Expand Down Expand Up @@ -183,7 +183,7 @@ class LoginState extends State<Login> {
settings: const RouteSettings(name: 'category_picker'),
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
pageBuilder: (context, _, __) => const CategoryPicker(),
pageBuilder: (context, _, __) => const LayoutPicker(),
));
},
child: const Text('Continue'),
Expand Down
29 changes: 23 additions & 6 deletions lib/widgets/picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@ import 'package:pheno_ui_tester/widgets/top_bar.dart';

import 'loading_screen.dart';

enum PickerEntryType {
tag,
layout,
}

class PickerEntry {
final PhenoDataEntry pde;
final PickerEntryType type;

const PickerEntry(this.pde, this.type);

String get id => pde.id;
String get uid => pde.uid;
String get name => pde.name;
String get path => pde.data['path'];
}

abstract class PickerWidget extends StatefulWidget {
const PickerWidget({super.key});
Future<List<PhenoDataEntry>> Function() get getList;
Widget Function(PhenoDataEntry, BuildContext, List<PhenoDataEntry>) get builder;
Future<void> Function(PhenoDataEntry)? get delete => null;
Future<List<PickerEntry>> Function() get getList;
Widget Function(PickerEntry, BuildContext, List<PickerEntry>) get builder;
Future<void> Function(PickerEntry)? get delete => null;
String get title;
}

class PickerState<T extends PickerWidget> extends State<T> {
List<PhenoDataEntry>? entries;
List<PickerEntry>? entries;
bool _loading = false;

PickerState();
Expand All @@ -39,8 +56,8 @@ class PickerState<T extends PickerWidget> extends State<T> {
}

List<Widget> children = (entries as List).map((e) => ListTile(
leading: const Icon(
Icons.screenshot,
leading: Icon(
e.type == PickerEntryType.tag ? Icons.folder_outlined : Icons.file_open_outlined,
size: 20,
),
trailing: widget.delete == null? null :IconButton(
Expand Down
9 changes: 4 additions & 5 deletions lib/widgets/render_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import 'package:flutter/material.dart';
import 'package:pheno_ui/interface/data/entry.dart';
import 'package:pheno_ui/interface/data/strapi_provider.dart';
import 'package:pheno_ui/pheno_ui.dart';
import 'package:pheno_ui_tester/widgets/picker_state.dart';
import 'package:pheno_ui_tester/widgets/top_bar.dart';

class RenderLayout extends StatefulWidget {
final String category;
final String tagId;
final String initialRoute;
final List<PhenoDataEntry> entries;

const RenderLayout({
super.key,
required this.category,
required this.tagId,
required this.initialRoute,
required this.entries,
});

@override
Expand All @@ -32,7 +31,7 @@ class RenderLayoutState extends State<RenderLayout> {
@override
void initState() {
super.initState();
var dataProvider = StrapiDataProvider(sourceId: Strapi().server, category: widget.category);
var dataProvider = StrapiDataProvider(sourceId: Strapi().server, category: widget.tagId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpicky but if this isn't strapi anymore should we rename the dataprovider to a more generic naming convention?

FigmaScreens().setProvider(dataProvider).then((_) => setState(() {
_initialized = true;
}));
Expand Down
47 changes: 0 additions & 47 deletions lib/widgets/screen_picker.dart

This file was deleted.

17 changes: 10 additions & 7 deletions lib/widgets/top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ Widget topBar(BuildContext context, [String? title, void Function()? refresh, Bo
var centerChildren = <Widget>[];

if (title != null) {
centerChildren.add(Text(
title,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 21,
overflow: TextOverflow.ellipsis,
centerChildren.add(FittedBox(
fit: BoxFit.fitWidth,
child: Text(
title,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 21,
overflow: TextOverflow.ellipsis,
),
),
));
}
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of these webview changes exactly? webviews seemed to work on iOS and I thought (although maybe I am misremembering) they worked on macOS as well?

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import Foundation
import path_provider_foundation
import screen_retriever
import shared_preferences_foundation
import webview_flutter_wkwebview
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
11 changes: 9 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- webview_flutter_wkwebview (0.0.1):
- Flutter
- FlutterMacOS
- window_manager (0.2.0):
- FlutterMacOS

Expand All @@ -16,6 +19,7 @@ DEPENDENCIES:
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- webview_flutter_wkwebview (from `Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin`)
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

EXTERNAL SOURCES:
Expand All @@ -27,14 +31,17 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
webview_flutter_wkwebview:
:path: Flutter/ephemeral/.symlinks/plugins/webview_flutter_wkwebview/darwin
window_manager:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
Expand Down
2 changes: 1 addition & 1 deletion macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
9 changes: 5 additions & 4 deletions package/pheno_ui/lib/interface/data/entry.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class PhenoDataEntry {
final int id;
final String uid;
const PhenoDataEntry(this.id, this.uid);
String get name => uid;
final Map<String, dynamic> data;
const PhenoDataEntry(this.data);
String get id => data['id'];
String get uid => data['path'];
String get name => data['name'];
}
12 changes: 6 additions & 6 deletions package/pheno_ui/lib/interface/data/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class PhenoDataProvider {
final String sourceId;
final String category;

final Map<int, Future<PhenoScreenSpec>> _screenSpecCache = {};
final Map<String, Future<PhenoScreenSpec>> _screenSpecCache = {};
final Map<String, Future<PhenoComponentSpec>> _componentSpecCache = {};
final Map<String, Future<LottieComposition>> _animationCache = {};
List<PhenoDataEntry>? _screenList;
Expand All @@ -39,7 +39,7 @@ abstract class PhenoDataProvider {
}

@nonVirtual
Future<PhenoScreenSpec> loadScreenLayout(int id) async {
Future<PhenoScreenSpec> loadScreenLayout(String id) async {
if (_screenSpecCache.containsKey(id)) {
return await _screenSpecCache[id]!;
}
Expand Down Expand Up @@ -69,10 +69,10 @@ abstract class PhenoDataProvider {
}

Future<List<PhenoDataEntry>> doGetScreenList();
Future<PhenoScreenSpec> doLoadScreenLayout(int id);
Future<PhenoScreenSpec> doLoadScreenLayout(String id);
Future<PhenoComponentSpec> doLoadComponentSpec(String name);
Future<LottieComposition> doLoadAnimation(String path);
Future<LottieComposition> doLoadAnimation(String id);

Image loadImage(String path, { required BoxFit fit });
SvgPicture loadSvg(String path, { required BoxFit fit });
Image loadImage(String id, { required BoxFit fit });
SvgPicture loadSvg(String id, { required BoxFit fit });
}
10 changes: 5 additions & 5 deletions package/pheno_ui/lib/interface/data/screen_spec.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class PhenoScreenSpec {
final int id;
final String id;
final String name;
final String slug;
final Map<String, dynamic> spec;
Expand All @@ -8,10 +8,10 @@ class PhenoScreenSpec {

factory PhenoScreenSpec.fromJson(Map<String, dynamic> json) {
return PhenoScreenSpec(
json['id'].toInt(),
json['attributes']['name'],
json['attributes']['slug'],
json['attributes']['spec']
json['id'],
json['name'],
json['tag']['path'] + '/' + json['name'],
json['data']
);
}
}
Loading