Skip to content

Commit

Permalink
Flutter 3 upgrade & MacosColor update (#248)
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

* chore: remove unused code
  • Loading branch information
GroovinChip authored May 13, 2022
1 parent 4bb29a8 commit e4c37d6
Show file tree
Hide file tree
Showing 77 changed files with 673 additions and 582 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [1.4.0]
* Migration to Flutter 3.0
* Minimum dart sdk version is now 2.17.0
* Use new super parameters feature
* Update to `flutter_lints: ^2.0.1` with subsequent fixes
* `MacosScrollbar` API more closely matches its material counterpart
* Update `MacosColor` to more closely match the `Color` class
* Adds `MacosColor.fromARGB` constructor
* Adds `MacosColor.fromRGBO` constructor
* Adds `alphaBlend` function
* Adds `getAlphaFromOpacity` function

## [1.3.0]
* Add a `top` property to `Sidebar`
* Tweak the default `primaryColor` value in `MacosThemeData`.
Expand Down
8 changes: 3 additions & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
include: package:flutter_lints/flutter.yaml

#linter:
# rules:
# - avoid_relative_lib_imports
# - prefer_const_constructors
# - use_key_in_widget_constructors
linter:
rules:
- use_super_parameters

analyzer:
plugins:
Expand Down
3 changes: 1 addition & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ linter:
# `// 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
286 changes: 158 additions & 128 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import 'package:provider/provider.dart';
import 'theme.dart';

void main() {
runApp(const MyApp());
runApp(const MacosUIGalleryApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
class MacosUIGalleryApp extends StatelessWidget {
const MacosUIGalleryApp({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -25,26 +25,26 @@ class MyApp extends StatelessWidget {
builder: (context, _) {
final appTheme = context.watch<AppTheme>();
return MacosApp(
title: 'macos_ui example',
title: 'macos_ui Widget Gallery',
theme: MacosThemeData.light(),
darkTheme: MacosThemeData.dark(),
themeMode: appTheme.mode,
debugShowCheckedModeBanner: false,
home: const Demo(),
home: const WidgetGallery(),
);
},
);
}
}

class Demo extends StatefulWidget {
const Demo({Key? key}) : super(key: key);
class WidgetGallery extends StatefulWidget {
const WidgetGallery({super.key});

@override
_DemoState createState() => _DemoState();
State<WidgetGallery> createState() => _WidgetGalleryState();
}

class _DemoState extends State<Demo> {
class _WidgetGalleryState extends State<WidgetGallery> {
double ratingValue = 0;
double sliderValue = 0;
bool value = false;
Expand Down Expand Up @@ -72,128 +72,158 @@ class _DemoState extends State<Demo> {

@override
Widget build(BuildContext context) {
return MacosWindow(
child: IndexedStack(
index: pageIndex,
children: pages,
),
// Optional title bar:
// titleBar: const TitleBar(
// title: Text('macOS App Name'),
// ),
sidebar: Sidebar(
top: MacosSearchField(
placeholder: 'Search',
controller: searchFieldController,
onResultSelected: (result) {
switch (result.searchKey) {
case 'Buttons':
setState(() {
pageIndex = 0;
searchFieldController.clear();
});
break;
case 'Indicators':
setState(() {
pageIndex = 1;
searchFieldController.clear();
});
break;
case 'Fields':
setState(() {
pageIndex = 2;
searchFieldController.clear();
});
break;
case 'Colors':
setState(() {
pageIndex = 3;
searchFieldController.clear();
});
break;
case 'Dialogs and Sheets':
setState(() {
pageIndex = 5;
searchFieldController.clear();
});
break;
case 'Toolbar':
setState(() {
pageIndex = 6;
searchFieldController.clear();
});
break;
case 'Selectors':
setState(() {
pageIndex = 7;
searchFieldController.clear();
});
break;
default:
searchFieldController.clear();
}
},
results: const [
SearchResultItem('Buttons'),
SearchResultItem('Indicators'),
SearchResultItem('Fields'),
SearchResultItem('Colors'),
SearchResultItem('Dialogs and Sheets'),
SearchResultItem('Toolbar'),
SearchResultItem('Selectors'),
return PlatformMenuBar(
menus: const [
PlatformMenu(
label: 'macos_ui Widget Gallery',
menus: [
PlatformProvidedMenuItem(
type: PlatformProvidedMenuItemType.about,
),
PlatformProvidedMenuItem(
type: PlatformProvidedMenuItemType.quit,
),
],
),
PlatformMenu(
label: 'View',
menus: [
PlatformProvidedMenuItem(
type: PlatformProvidedMenuItemType.toggleFullScreen,
),
],
),
PlatformMenu(
label: 'Window',
menus: [
PlatformProvidedMenuItem(
type: PlatformProvidedMenuItemType.minimizeWindow,
),
PlatformProvidedMenuItem(
type: PlatformProvidedMenuItemType.zoomWindow,
),
],
),
minWidth: 200,
builder: (context, controller) {
return SidebarItems(
currentIndex: pageIndex,
onChanged: (i) => setState(() => pageIndex = i),
scrollController: controller,
items: const [
SidebarItem(
leading: MacosIcon(CupertinoIcons.square_on_circle),
label: Text('Buttons'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.arrow_2_circlepath),
label: Text('Indicators'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.textbox),
label: Text('Fields'),
),
SidebarItem(
label: Text('Disclosure'),
disclosureItems: [
SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
label: Text('Colors'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
label: Text('Item 3'),
),
],
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.rectangle),
label: Text('Dialogs & Sheets'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.macwindow),
label: Text('Toolbar'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.calendar),
label: Text('Selectors'),
),
],
body: MacosWindow(
sidebar: Sidebar(
top: MacosSearchField(
placeholder: 'Search',
controller: searchFieldController,
onResultSelected: (result) {
switch (result.searchKey) {
case 'Buttons':
setState(() {
pageIndex = 0;
searchFieldController.clear();
});
break;
case 'Indicators':
setState(() {
pageIndex = 1;
searchFieldController.clear();
});
break;
case 'Fields':
setState(() {
pageIndex = 2;
searchFieldController.clear();
});
break;
case 'Colors':
setState(() {
pageIndex = 3;
searchFieldController.clear();
});
break;
case 'Dialogs and Sheets':
setState(() {
pageIndex = 5;
searchFieldController.clear();
});
break;
case 'Toolbar':
setState(() {
pageIndex = 6;
searchFieldController.clear();
});
break;
case 'Selectors':
setState(() {
pageIndex = 7;
searchFieldController.clear();
});
break;
default:
searchFieldController.clear();
}
},
results: const [
SearchResultItem('Buttons'),
SearchResultItem('Indicators'),
SearchResultItem('Fields'),
SearchResultItem('Colors'),
SearchResultItem('Dialogs and Sheets'),
SearchResultItem('Toolbar'),
SearchResultItem('Selectors'),
],
);
},
bottom: const MacosListTile(
leading: MacosIcon(CupertinoIcons.profile_circled),
title: Text('Tim Apple'),
subtitle: Text('tim@apple.com'),
),
minWidth: 200,
builder: (context, controller) {
return SidebarItems(
currentIndex: pageIndex,
onChanged: (i) => setState(() => pageIndex = i),
scrollController: controller,
items: const [
SidebarItem(
leading: MacosIcon(CupertinoIcons.square_on_circle),
label: Text('Buttons'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.arrow_2_circlepath),
label: Text('Indicators'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.textbox),
label: Text('Fields'),
),
SidebarItem(
label: Text('Disclosure'),
disclosureItems: [
SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
label: Text('Colors'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
label: Text('Item 3'),
),
],
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.rectangle),
label: Text('Dialogs & Sheets'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.macwindow),
label: Text('Toolbar'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.calendar),
label: Text('Selectors'),
),
],
);
},
bottom: const MacosListTile(
leading: MacosIcon(CupertinoIcons.profile_circled),
title: Text('Tim Apple'),
subtitle: Text('tim@apple.com'),
),
),
child: IndexedStack(
index: pageIndex,
children: pages,
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/buttons_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'package:provider/provider.dart';
import '../theme.dart';

class ButtonsPage extends StatefulWidget {
const ButtonsPage({Key? key}) : super(key: key);
const ButtonsPage({super.key});

@override
_ButtonsPageState createState() => _ButtonsPageState();
State<ButtonsPage> createState() => _ButtonsPageState();
}

class _ButtonsPageState extends State<ButtonsPage> {
Expand Down
Loading

0 comments on commit e4c37d6

Please sign in to comment.