Closed jmatth closed 1 year ago
Been trying to make this work on web and I think this it be more trouble than its worth. We may need to make it clear that from 2.0 on, it is expected that macos_ui
only be used on macOS.
Indeed, I too believe that supporting only macOS (and providing a web playground for showcasing the components) would be optimal going forward.
I've got it sort of working on web:
Theming is borked for some reason
EDIT: only dark theme is borked, light looks fine:
Minimum reproducible sample using 2.0.0-beta.9
:
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MacosApp(
title: 'Flutter Demo',
theme: MacosThemeData.light(),
darkTheme: MacosThemeData.dark(),
themeMode: ThemeMode.dark,
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return MacosWindow(
child: MacosScaffold(
children: [
ContentArea(
builder: (context, _) => const Center(child: Text('Content')),
),
],
),
);
}
}
Description
Launching the app on non-macOS platforms results in immediate exceptions. I've so far tested on Windows and Chrome, but based on the exceptions I'm almost certain the same errors will occur on any platform other than macOS
Steps To Reproduce
macos
.Expected behavior
Example app should open and display the widgets gallery.
Actual behavior
An exception is immediately thrown. Since the exception is thrown in
main
beforerunApp
is called, the app seemingly freezes with a blank screen without even displaying Flutter's red error screen in debug mode.Screenshots
Windows
Chrome
Logs
Logs
Logs generated without `--verbose` since doing so adds a bunch of useless noise that pushes the comment length above Github's limit. ``` Launching lib\main.dart on Windows in debug mode... Building Windows application... 6.6s √ Built build\windows\runner\Debug\example.exe. [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel macos_window_utils/window_manipulator) #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)Further details
The initial exception comes from an unconditional call into
macos_window_utils
right at the top of main. Since that plugin understandably only supports macOS, this call throws. After fixing this the app is still broken due to an unconditional use ofPlatformMenuBar
, which is again only supported on macOS. Adding conditional logic to only execute this code on macOS allows the example app to run.Edit: for web, an additional fix is needed to prevent accessing
Platform.isMacOS
inutils.dart
.