Skip to content

Commit

Permalink
Merge pull request #92 from fluttercandies/support-macos
Browse files Browse the repository at this point in the history
Support macOS
  • Loading branch information
CaiJingLong committed Jul 18, 2022
2 parents e2789a3 + bbf5fd3 commit c9ecd03
Show file tree
Hide file tree
Showing 49 changed files with 3,747 additions and 58 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/runnable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ jobs:
- run: flutter pub get
- run: sudo echo "y" | sudo $ANDROID_HOME/tools/bin/sdkmanager "ndk;21.4.7075529"
- run: cd example; flutter build apk --debug

test_macOS:
needs: analyze
name: Test macOS build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest ]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '11.x'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- run: dart --version
- run: flutter --version
- run: flutter pub get
- run: cd example; flutter build macos --debug
70 changes: 38 additions & 32 deletions example/lib/add_text_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,50 @@ class _AddTextPageState extends State<AddTextPage> {
],
),
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () async {
await addText(fontName);
},
child: const Text('add'),
),
ElevatedButton(
onPressed: () async {
await addText('');
},
child: const Text('add use defaultFont'),
),
],
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
await addText(fontName);
},
child: const Text('add text'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
await addText('');
},
child: const Text('add use defaultFont'),
),
),
ElevatedButton(
child: Text('download and register font'),
onPressed: () async {
final aliFontUrl =
'https://cdn.jsdelivr.net/gh/kikt-blog/ali_font@master/Alibaba-PuHuiTi-Medium.ttf';
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
child: Text('download and register font'),
onPressed: () async {
final aliFontUrl =
'https://cdn.jsdelivr.net/gh/kikt-blog/ali_font@master/Alibaba-PuHuiTi-Medium.ttf';

final body = await http.get(Uri.parse(aliFontUrl));
final body = await http.get(Uri.parse(aliFontUrl));

final tmpDir = await pp.getTemporaryDirectory();
final f = File(
'${tmpDir.absolute.path}/${DateTime.now().millisecondsSinceEpoch}.ttf');
f.writeAsBytesSync(body.bodyBytes);
final tmpDir = await pp.getTemporaryDirectory();
final f = File(
'${tmpDir.absolute.path}/${DateTime.now().millisecondsSinceEpoch}.ttf');
f.writeAsBytesSync(body.bodyBytes);

fontName = await FontManager.registerFont(f);
fontName = await FontManager.registerFont(f);

showToast('register $fontName success');
},
showToast('register $fontName success');
},
),
),
TextField(
controller: _controller,
Padding(
padding: const EdgeInsets.all(16),
child: TextField(
controller: _controller,
),
),
// Slider(value: null, onChanged: null),
],
Expand Down
14 changes: 9 additions & 5 deletions example/lib/draw_example_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ class _DrawExamplePageState extends State<DrawExamplePage> {
],
),
),
addLine(),
addRect(),
addOval(),
addPoints(),
buildDrawPath(),
...[addLine(), addRect(), addOval(), addPoints(), buildDrawPath()]
.map(
(e) => Container(
width: 200,
height: 48,
margin: const EdgeInsets.all(8),
child: e,
),
),
],
),
);
Expand Down
7 changes: 0 additions & 7 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,3 @@ class _SimpleExamplePageState extends State<SimpleExamplePage> {
setProvider(img);
}
}

Widget buildButton(String text, VoidCallback onTap) {
return TextButton(
child: Text(text),
onPressed: onTap,
);
}
33 changes: 22 additions & 11 deletions example/lib/widget/examples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,32 @@ class _ExamplesState extends State<Examples> {

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: widgets.length,
itemBuilder: (BuildContext context, int index) {
return _buildButton(widgets[index]);
},
return Column(
children: widgets.map((e) => _buildButton(e)).toList(),
);
}

Widget _buildButton(Widget widget) {
return ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute<void>(builder: (BuildContext ctx) => widget));
},
child: Text(widget.runtimeType.toString()),
return Align(
alignment: Alignment.center,
child: Container(
margin: const EdgeInsets.only(top: 16),
width: 300,
height: 48,
child: ElevatedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute<void>(builder: (BuildContext ctx) => widget));
},
child: Text(toTitle(widget)),
),
),
);
}

String toTitle(Widget widget) {
final src = widget.runtimeType.toString();
final regex = RegExp('([A-Z]){1}[a-z]+');
return regex.allMatches(src).map((e) => e.group(0)).join(' ');
}
}
6 changes: 6 additions & 0 deletions example/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/xcuserdata/
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Debug.xcconfig
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"
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Release.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"
14 changes: 14 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Generated file. Do not edit.
//

import FlutterMacOS
import Foundation

import image_editor
import path_provider_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ImageEditorPlugin.register(with: registry.registrar(forPlugin: "ImageEditorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
40 changes: 40 additions & 0 deletions example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
platform :osx, '10.15'

# 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 c9ecd03

Please sign in to comment.