Skip to content

Commit

Permalink
feat: platform theme add, platform filled button macos fontSize adjus…
Browse files Browse the repository at this point in the history
…tment
  • Loading branch information
KRTirtho committed Oct 31, 2022
1 parent b295739 commit a5d845f
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/platform_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export 'src/platform_tab_view.dart';
export 'src/platform_property.dart';
export 'src/platform_app_bar.dart';
export 'src/platform_sidebar.dart';
export 'src/platform_theme.dart';
18 changes: 13 additions & 5 deletions lib/src/platform_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/src/platform_app_router.dart';
import 'package:platform_ui/src/platform_mixin.dart';
import 'package:platform_ui/src/platform_property.dart';
import 'package:platform_ui/src/platform_theme.dart';

// TODO: Implement [PlatformTheme]

Expand Down Expand Up @@ -139,7 +140,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
routeInformationParser: routeInformationParser,
routerDelegate: routerDelegate,
backButtonDispatcher: backButtonDispatcher,
builder: builder,
builder: buildPlatformTheme,
title: title,
onGenerateTitle: onGenerateTitle,
androidTheme: androidTheme,
Expand Down Expand Up @@ -178,6 +179,13 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
);
}

static Widget buildPlatformTheme(BuildContext context, Widget? child) {
return PlatformTheme(
theme: PlatformThemeData.fromContext(context),
child: child ?? Container(),
);
}

@override
Widget android(context) {
return MaterialApp(
Expand All @@ -190,7 +198,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: builder,
builder: buildPlatformTheme,
title: title,
onGenerateTitle: onGenerateTitle,
theme: androidTheme,
Expand Down Expand Up @@ -235,7 +243,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: builder,
builder: buildPlatformTheme,
title: title,
onGenerateTitle: onGenerateTitle,
theme: iosTheme,
Expand Down Expand Up @@ -280,7 +288,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: builder,
builder: buildPlatformTheme,
title: title,
onGenerateTitle: onGenerateTitle,
theme: macosTheme,
Expand Down Expand Up @@ -321,7 +329,7 @@ class PlatformApp extends StatelessWidget with PlatformMixin<Widget> {
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: navigatorObservers!,
builder: builder,
builder: buildPlatformTheme,
title: title,
onGenerateTitle: onGenerateTitle,
theme: windowsTheme,
Expand Down
44 changes: 30 additions & 14 deletions lib/src/platform_filled_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,36 @@ class PlatformFilledButton extends StatelessWidget with PlatformMixin<Widget> {
cursor: mouseCursor,
child: GestureDetector(
onLongPress: onLongPress,
child: PushButton(
onPressed: onPressed,
pressedOpacity: macOSiOSPressedOpacity,
borderRadius:
borderRadius ?? const BorderRadius.all(Radius.circular(4.0)),
buttonSize: macOSButtonSize,
isSecondary: macOSIsSecondary,
mouseCursor: mouseCursor,
color: style?.backgroundColor?.resolve(allStates),
disabledColor:
style?.backgroundColor?.resolve({MaterialState.disabled}) ??
CupertinoColors.quaternarySystemFill,
padding: style?.padding?.resolve(allStates),
child: child,
child: IconTheme(
data: IconTheme.of(context).copyWith(
color:
style?.foregroundColor?.resolve(Utils.allMaterialStates) ??
MacosTheme.of(context).pushButtonTheme.secondaryColor,
),
child: PushButton(
onPressed: onPressed,
pressedOpacity: macOSiOSPressedOpacity,
borderRadius: borderRadius ??
const BorderRadius.all(Radius.circular(4.0)),
buttonSize: macOSButtonSize,
isSecondary: macOSIsSecondary,
mouseCursor: mouseCursor,
color: style?.backgroundColor?.resolve(allStates),
disabledColor:
style?.backgroundColor?.resolve({MaterialState.disabled}) ??
CupertinoColors.quaternarySystemFill,
padding: style?.padding?.resolve(allStates),
child: DefaultTextStyle(
style: MacosTheme.of(context).typography.body.copyWith(
color: style?.foregroundColor
?.resolve(Utils.allMaterialStates) ??
MacosTheme.of(context)
.pushButtonTheme
.secondaryColor,
),
child: child,
),
),
),
),
),
Expand Down
20 changes: 19 additions & 1 deletion lib/src/platform_property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ class PlatformProperty<T> {
}
}

factory PlatformProperty.only({
T? android,
T? ios,
T? macos,
T? linux,
T? windows,
required T other,
}) {
return PlatformProperty(
android: android ?? other,
ios: ios ?? other,
macos: macos ?? other,
linux: linux ?? other,
windows: windows ?? other,
);
}

factory PlatformProperty.all(T value) {
return PlatformProperty(
android: value,
Expand Down Expand Up @@ -59,7 +76,8 @@ class PlatformProperty<T> {
Map<T, Set<TargetPlatform>> groups) {
assert(groups.isNotEmpty);

final platforms = TargetPlatform.values..remove(TargetPlatform.fuchsia);
final platforms = List.from(TargetPlatform.values)
..remove(TargetPlatform.fuchsia);
assert(groups.values.expand<TargetPlatform>((element) => element).length ==
platforms.length);

Expand Down
17 changes: 14 additions & 3 deletions lib/src/platform_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:collection/collection.dart';

class PlatformSidebarItem {
final Widget title;
Expand All @@ -25,10 +26,18 @@ class PlatformSidebarItem {
);
}

SidebarItem macos() {
SidebarItem macos(BuildContext context, bool isActive) {
return SidebarItem(
label: title,
leading: icon,
leading: IconTheme(
data: IconTheme.of(context).copyWith(
color: isActive
? MacosTheme.of(context).canvasColor
: MacosTheme.of(context).primaryColor,
size: 16,
),
child: icon,
),
);
}

Expand Down Expand Up @@ -207,7 +216,9 @@ class _PlatformSidebarState extends State<PlatformSidebar>
return SidebarItems(
currentIndex: currentIndex,
onChanged: onIndexChanged,
items: widget.body.keys.map((e) => e.macos()).toList(),
items: widget.body.keys
.mapIndexed((i, e) => e.macos(context, i == currentIndex))
.toList(),
);
},
),
Expand Down
36 changes: 35 additions & 1 deletion lib/src/platform_text_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:fluent_ui/fluent_ui.dart' as FluentUI;
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/platform_ui.dart';
import "package:platform_ui/src/utils.dart";

Expand Down Expand Up @@ -108,7 +109,40 @@ class PlatformTextButton extends StatelessWidget with PlatformMixin<Widget> {

@override
Widget macos(context) {
return ios(context);
return ClipRect(
clipBehavior: clipBehavior,
child: Focus(
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
onHover: onHover,
cursor: mouseCursor,
child: GestureDetector(
onLongPress: onLongPress,
child: CupertinoButton(
color: style?.foregroundColor?.resolve(allStates),
onPressed: onPressed,
pressedOpacity: macOSiOSPressedOpacity,
borderRadius:
borderRadius ?? const BorderRadius.all(Radius.circular(8.0)),
minSize: style?.minimumSize?.resolve(allStates)?.width,
disabledColor:
style?.backgroundColor?.resolve({MaterialState.disabled}) ??
CupertinoColors.quaternarySystemFill,
padding: style?.padding?.resolve(allStates),
child: DefaultTextStyle(
style: MacosTheme.of(context).typography.body.copyWith(
color: style?.foregroundColor
?.resolve(Utils.allMaterialStates) ??
MacosTheme.of(context).primaryColor,
),
child: child,
),
),
),
),
),
);
}

@override
Expand Down
Loading

0 comments on commit a5d845f

Please sign in to comment.