Skip to content

Commit

Permalink
Replace testbed/ with plugin examples (#913)
Browse files Browse the repository at this point in the history
The testbed/ directory is a relic of a much earlier stage of desktop development, when maintaining apps was cumbersome (because they had to be recreated from scratch on a regular basis, before the template stabilized) and it was useful to have a desktop-enabled example handy for basic functionality like scrolling and typing that were still being implemented.

This removes testbed/, and replaces it with standard in-package examples for the two remaining plugins (the other purpose of testbed). Each is created with `flutter create -t plugin .` with the following changes:
- Removed all the template comments.
- Removed the template-standard used of `flutter_lints` (as the repo uses flutter/plugins-based lints).
- Added the copyright notice.
- Changed the example Dart code:
  - `menubar`'s example is the counter app, but with the resize-on-launch logic taken from `testbed`.
  - `testbed`'s example is testbed's code, but with the keyboard and scrolling parts removed.
- Changed the template-standard integration test to be a simple sanity check that calling the plugin works.
- Removed the (new!) template-standard macOS native unit tests, since backfilling unit tests is out of scope here. The scaffolding is still in place in case we want to add some later.

Having the standard example structure will make the plugins easier to maintain when we do need to touch them, and easier for people to find out how to use.

Tangential change:
- Updates the CI hosts since the macOS and Linux hosts that were there are deprecated.
  • Loading branch information
stuartmorgan authored Jan 9, 2023
1 parent 17d4710 commit 6c66ad2
Show file tree
Hide file tree
Showing 153 changed files with 4,871 additions and 1,465 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macOS-10.15, windows-2019, ubuntu-18.04]
os: [macOS-12, windows-2019, ubuntu-22.04]
include:
- os: macOS-10.15
- os: macOS-12
TARGET: macos
- os: ubuntu-18.04
- os: ubuntu-22.04
TARGET: linux
- os: windows-2019
TARGET: windows
Expand Down Expand Up @@ -52,13 +52,23 @@ jobs:
- name: Doctor
# Run doctor, for ease of debugging any issues.
run: flutter doctor -v
- name: Build testbed debug
- name: Build menubar debug
run: |
flutter packages get
flutter build -v ${{matrix.TARGET}} --debug
working-directory: ${{ github.workspace }}/fde/testbed
- name: Build testbed release
working-directory: ${{ github.workspace }}/fde/plugins/menubar/example
- name: Build menubar release
run: |
flutter packages get
flutter build -v ${{matrix.TARGET}} --release
working-directory: ${{ github.workspace }}/fde/testbed
working-directory: ${{ github.workspace }}/fde/plugins/menubar/example
- name: Build window_size debug
run: |
flutter packages get
flutter build -v ${{matrix.TARGET}} --debug
working-directory: ${{ github.workspace }}/fde/plugins/window_size/example
- name: Build window_size release
run: |
flutter packages get
flutter build -v ${{matrix.TARGET}} --release
working-directory: ${{ github.workspace }}/fde/plugins/window_size/example
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ please file issues here.
The `plugins` directory contains all the plugins. See
[its README](plugins/README.md) to get started.

`testbed` is a a simple test application for the plugins above.

## Caveats

* This is not an officially supported Google product.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ linter:
- empty_statements
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- join_return_with_assignment
- library_names
Expand Down
44 changes: 44 additions & 0 deletions plugins/menubar/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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/

# 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
16 changes: 16 additions & 0 deletions plugins/menubar/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# menubar_example

Demonstrates how to use the menubar plugin.

## Getting Started

This project is a starting point for a Flutter application.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'package:menubar/menubar.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('sanity check', (tester) async {
expect(
setApplicationMenu([
NativeSubmenu(label: 'Test', children: [
NativeMenuItem(
label: '1',
shortcut: LogicalKeySet(
LogicalKeyboardKey.meta, LogicalKeyboardKey.keyA),
onSelected: () {}),
const NativeMenuDivider(),
NativeSubmenu(label: 'Presets', children: [
NativeMenuItem(
label: '2',
shortcut: LogicalKeySet(LogicalKeyboardKey.meta,
LogicalKeyboardKey.shift, LogicalKeyboardKey.keyB),
onSelected: null),
])
]),
]),
completes);
});
}
98 changes: 7 additions & 91 deletions testbed/lib/main.dart → plugins/menubar/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,13 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'dart:io' show Platform;
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:menubar/menubar.dart';
import 'package:window_size/window_size.dart' as window_size;

import 'keyboard_test_page.dart';

void main() {
// Try to resize and reposition the window to be half the width and height
// of its screen, centered horizontally and shifted up from center.
WidgetsFlutterBinding.ensureInitialized();
window_size.getWindowInfo().then((window) {
final screen = window.screen;
if (screen != null) {
final screenFrame = screen.visibleFrame;
final width = math.max((screenFrame.width / 2).roundToDouble(), 800.0);
final height = math.max((screenFrame.height / 2).roundToDouble(), 600.0);
final left = ((screenFrame.width - width) / 2).roundToDouble();
final top = ((screenFrame.height - height) / 3).roundToDouble();
final frame = Rect.fromLTWH(left, top, width, height);
window_size.setWindowFrame(frame);
window_size.setWindowMinSize(Size(0.8 * width, 0.8 * height));
window_size.setWindowMaxSize(Size(1.5 * width, 1.5 * height));
window_size
.setWindowTitle('Flutter Testbed on ${Platform.operatingSystem}');
}
});

runApp(new MyApp());
runApp(const MyApp());
}

/// Top level widget for the application.
Expand All @@ -52,7 +26,7 @@ class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_AppState createState() => new _AppState();
State<MyApp> createState() => _AppState();
}

class _AppState extends State<MyApp> {
Expand Down Expand Up @@ -96,7 +70,7 @@ class _AppState extends State<MyApp> {
: () {
setPrimaryColor(Colors.blue);
}),
NativeMenuDivider(),
const NativeMenuDivider(),
NativeSubmenu(label: 'Presets', children: [
NativeMenuItem(
label: 'Red',
Expand Down Expand Up @@ -137,7 +111,7 @@ class _AppState extends State<MyApp> {
: () {
_setCounter(0);
}),
NativeMenuDivider(),
const NativeMenuDivider(),
NativeMenuItem(
label: 'Increment',
shortcut: LogicalKeySet(LogicalKeyboardKey.f2),
Expand Down Expand Up @@ -193,36 +167,9 @@ class _MyHomePage extends StatelessWidget {
const Text(
'You have pushed the button this many times:',
),
new Text(
Text(
'$counter',
style: Theme.of(context).textTheme.headline4,
),
TextInputTestWidget(),
new ElevatedButton(
child: new Text('Test raw keyboard events'),
onPressed: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => KeyboardTestPage()));
},
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 380.0,
height: 100.0,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 1.0)),
child: Scrollbar(
child: ListView.builder(
padding: EdgeInsets.all(8.0),
itemExtent: 20.0,
itemCount: 50,
itemBuilder: (context, index) {
return Text('entry $index');
},
),
),
),
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
Expand All @@ -234,38 +181,7 @@ class _MyHomePage extends StatelessWidget {
floatingActionButton: FloatingActionButton(
onPressed: _AppState.of(context)!.incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}

/// A widget containing controls to test text input.
class TextInputTestWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
SampleTextField(),
SampleTextField(),
],
);
}
}

/// A text field with styling suitable for including in a TextInputTestWidget.
class SampleTextField extends StatelessWidget {
/// Creates a new sample text field.
const SampleTextField();

@override
Widget build(BuildContext context) {
return Container(
width: 200.0,
padding: const EdgeInsets.all(10.0),
child: TextField(
decoration: InputDecoration(border: OutlineInputBorder()),
child: const Icon(Icons.add),
),
);
}
Expand Down
File renamed without changes.
Loading

0 comments on commit 6c66ad2

Please sign in to comment.