Skip to content

Instantly share code, notes, and snippets.

@instance-id
Created February 11, 2022 00:52
Show Gist options
  • Save instance-id/05e3e805f8b28fa86f427be7c7efde14 to your computer and use it in GitHub Desktop.
Save instance-id/05e3e805f8b28fa86f427be7c7efde14 to your computer and use it in GitHub Desktop.
Minimal Rust / Flutter project utilizing NativeShell, libadwaita, and adwaita
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:libadwaita/libadwaita.dart';
import 'package:nativeshell/nativeshell.dart';
import 'package:adwaita/adwaita.dart';
import 'package:window_decorations/window_decorations.dart';
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AdwaitaThemeData.dark(),
home: DefaultTextStyle(
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
child: Container(
color: Colors.black,
child: WindowWidget(
onCreateState: (initData) {
WindowState? state;
state ??= MainWindowState();
return state;
},
),
),
),
);
}
}
class MainWindowState extends WindowState {
@override
Future<void> initializeWindow(Size intrinsicContentSize) async {
await window.setStyle(WindowStyle(canResize: true, frame: WindowFrame.noTitle));
await window.show();
}
@override
WindowSizingMode get windowSizingMode =>
WindowSizingMode.atLeastIntrinsicSize;
final ThemeType _currentThemeType = ThemeType.auto;
@override
Widget build(BuildContext context) {
return WindowLayoutProbe(
child: Column(mainAxisSize: MainAxisSize.max, children: [
AdwHeaderBar.minimalNativeshell(height: 30, window: window, start: [
Builder(builder: (context) {
return AdwHeaderButton(
icon: const Icon(Icons.view_sidebar, size: 15),
// isActive: _flapController.isOpen,
onPressed: () {
// _flapController.toggle();
});
})
], end: [
DecoratedMinimizeButton(
width: 25,
type: _currentThemeType,
onPressed: () => debugPrint('Minimize Window'),
),
DecoratedMaximizeButton(
width: 25,
type: _currentThemeType,
onPressed: () => debugPrint('Maximize Window'),
),
DecoratedCloseButton(
width: 25,
type: _currentThemeType,
onPressed: () => debugPrint('Close Window'),
)
]),
Container(
padding: EdgeInsets.all(20),
child: Center(child: Text('Welcome to NativeShell!')),
)
]));
}
}
version: 1.0.0+1
environment:
sdk: ">=2.12.0-214.0.dev <3.0.0"
dependencies:
flutter:
sdk: flutter
pedantic: ^1.9.2
path: ^1.7.0
# Not sure if you *need* all of these, some were left over from the
# original NativeShell example, which was more complex than this
cupertino_icons: ^1.0.4
nativeshell: ^0.1.13
adwaita:
libadwaita:
window_decorations: ^2.0.0
path_provider: ^2.0.8
package_info_plus: ^1.3.0
shared_preferences: ^2.0.13
# I had to comment this out as I can't compile with this for some reason.
# Same reason I could not use the fix46 branch. Some sort of dependency confliction
# url_launcher: ^6.0.6
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
@instance-id
Copy link
Author

instance-id commented Feb 11, 2022

The above produces this minimal example, which could be built upon:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment