Skip to content

Commit

Permalink
Starter app (macosui#251)
Browse files Browse the repository at this point in the history
* chore: Update pubspec.yaml files to support Flutter 3

* chore: run dart fix --apply

* chore: migrate Scrollbar to Flutter 3

* chore: update flutter_lints & subsequent fixes

* feat: add missing functions to MacosColor

the Color class has a number of functions that MacosColor had not implemented

* chore: use super parameters

* chore: update changelog

* chore: tweak example app

Uses the new PlatformMenuBar. Also update product name.

* chore: small changelog tweak

* chore: run flutter format .

* chore: run dart fix --apply

* chore: run flutter format .

* chore: remove unused code in example

* chore: remove unused import

* feat: first pass at starter app brick

* chore: improve starter app brick

* chore: fix widget test in starter app

* feat: conditional prompts & running pub get

* chore: finalize brick

* chore: run flutter format

* chore: exclude starter app from analyzer
  • Loading branch information
GroovinChip committed May 13, 2022
1 parent ac6870c commit ab47743
Show file tree
Hide file tree
Showing 46 changed files with 2,212 additions and 0 deletions.
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ linter:
analyzer:
plugins:
- dart_code_metrics
exclude:
- starter_app/**

dart_code_metrics:
metrics:
Expand Down
6 changes: 6 additions & 0 deletions starter_app/bricks/macosui_starter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 1.0.0

* Initial release 🎉
* Generate a new Flutter application that uses `macos_ui`
* Optionally use window translucency
* Optionally hide the native titlebar
21 changes: 21 additions & 0 deletions starter_app/bricks/macosui_starter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2021] [Reuben Turner]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions starter_app/bricks/macosui_starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# macosui_starter

![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)

A starter Flutter application for macOS that uses [`macos_ui`](https://pub.dev/packages/macos_ui).

<img src='https://imgur.com/rG4uDKs.png' />

## 🚧 Prerequisites
* Your Flutter version should be at least 3.0
* You should have `mason_cli` installed

## Usage 🚀
```sh
mason make macosui_starter
```

You'll be prompted for the following information:
* The name of your app
* Your app's description
* The name of your organization
* Whether to use window transclucency
* Whether to show or hide the native titlebar

⚠️ **Please note**: if you opt to use window transclucency you will not be asked if you want to show or hide the native
titlebar, as it will be hidden by default.

## Variables ✨

| Variable | Description | Default | Type |
|-------------------|-------------------------------------|---------------------------------------------------------|-----------|
| `app_name` | The name of your app | `macosui_starter` | `string` |
| `app_description` | The description of your application | `A starter Flutter application for macOS with macos_ui` | `string` |
| `org_name` | The name of your organization | `com.example` | `string` |
| `use_translucency`| Whether to use window transclucency | `false` | `boolean` |

## Output 📦

A Flutter application that:
* Targets macOS (support for other platforms can be added manually)
* Has `macos_ui` pre-installed
* Builds basic UI based on the latest version of `macos_ui`
47 changes: 47 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
- platform: macos
create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851
base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
17 changes: 17 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# {{ app_name }}

A starter Flutter app for macOS with `macos_ui`.

## Getting Started

This project is a starting point for a Flutter application specifically targeting macOS and uses the `macos_ui` plugin
to achieve UI and UX that match their native AppKit counterparts as closely as possible.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
30 changes: 30 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
- use_super_parameters

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
98 changes: 98 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';

void main() {
runApp(const App());
}

class App extends StatelessWidget {
const App({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MacosApp(
title: '{{ app_name }}',
theme: MacosThemeData.light(),
darkTheme: MacosThemeData.dark(),
themeMode: ThemeMode.system,
home: const MainView(),
);
}
}

class MainView extends StatefulWidget {
const MainView({super.key});

@override
State<MainView> createState() => _MainViewState();
}

class _MainViewState extends State<MainView> {
int _pageIndex = 0;

@override
Widget build(BuildContext context) {
return MacosWindow(
sidebar: Sidebar(
minWidth: 200,
builder: (context, scrollController) => SidebarItems(
currentIndex: _pageIndex,
onChanged: (index) {
setState(() => _pageIndex = index);
},
items: const [
SidebarItem(
leading: MacosIcon(CupertinoIcons.home),
label: Text('Home'),
),
],
),
),
child: IndexedStack(
index: _pageIndex,
children: const [
HomePage(),
],
),
);
}
}

class HomePage extends StatelessWidget {
const HomePage({super.key});

@override
Widget build(BuildContext context) {
return Builder(
builder: (context) {
return MacosScaffold(
toolBar: ToolBar(
title: const Text('Home'),
actions: [
ToolBarIconButton(
label: 'Toggle Sidebar',
icon: const MacosIcon(CupertinoIcons.sidebar_left),
showLabel: false,
tooltipMessage: 'Toggle Sidebar',
onPressed: () {
MacosWindowScope.of(context).toggleSidebar();
},
)
],
),
children: [
ContentArea(
builder: (context, scrollController) {
return const Center(
child: Text('Home'),
);
},
),
],
);
},
);
}
}
7 changes: 7 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/dgph
**/xcuserdata/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Generated file. Do not edit.
//

import FlutterMacOS
import Foundation

import macos_ui

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MacOSUiPlugin.register(with: registry.registrar(forPlugin: "MacOSUiPlugin"))
}
40 changes: 40 additions & 0 deletions starter_app/bricks/macosui_starter/__brick__/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
platform :osx, '10.11'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
Loading

0 comments on commit ab47743

Please sign in to comment.