-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// ignore_for_file: library_prefixes | ||
|
||
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:platform_ui/platform_ui.dart'; | ||
import "package:platform_ui/src/utils.dart"; | ||
|
||
class PlatformTextButton extends StatelessWidget with PlatformMixin<Widget> { | ||
final VoidCallback? onPressed; | ||
final VoidCallback? onLongPress; | ||
final void Function(PointerHoverEvent)? onHover; | ||
final ValueChanged<bool>? onFocusChange; | ||
final ButtonStyle? style; | ||
final Clip clipBehavior; | ||
final FocusNode? focusNode; | ||
final bool autofocus; | ||
final Widget child; | ||
final double macOSiOSPressedOpacity; | ||
final MouseCursor mouseCursor; | ||
|
||
const PlatformTextButton({ | ||
Key? key, | ||
required this.child, | ||
required this.onPressed, | ||
this.onLongPress, | ||
this.onFocusChange, | ||
this.style, | ||
this.focusNode, | ||
this.autofocus = false, | ||
this.clipBehavior = Clip.none, | ||
this.mouseCursor = SystemMouseCursors.click, | ||
this.onHover, | ||
this.macOSiOSPressedOpacity = .4, | ||
}) : super(key: key); | ||
|
||
final allStates = const { | ||
MaterialState.focused, | ||
MaterialState.disabled, | ||
MaterialState.error, | ||
MaterialState.hovered, | ||
MaterialState.pressed, | ||
MaterialState.selected, | ||
}; | ||
|
||
@override | ||
Widget android() { | ||
return MouseRegion( | ||
onHover: onHover, | ||
cursor: mouseCursor, | ||
child: TextButton( | ||
onPressed: onPressed, | ||
onLongPress: onLongPress, | ||
onFocusChange: onFocusChange, | ||
style: style, | ||
clipBehavior: clipBehavior, | ||
focusNode: focusNode, | ||
autofocus: autofocus, | ||
child: child, | ||
), | ||
); | ||
} | ||
|
||
BorderRadius? get borderRadius { | ||
final shape = style?.shape?.resolve(allStates); | ||
if (shape is RoundedRectangleBorder && shape.borderRadius is BorderRadius) { | ||
return shape.borderRadius as BorderRadius; | ||
} | ||
return null; | ||
} | ||
|
||
@override | ||
Widget ios() { | ||
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: child, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget linux() { | ||
return android(); | ||
} | ||
|
||
@override | ||
Widget macos() { | ||
return ios(); | ||
} | ||
|
||
@override | ||
Widget windows() { | ||
return ClipRect( | ||
clipBehavior: clipBehavior, | ||
child: MouseRegion( | ||
cursor: mouseCursor, | ||
onHover: onHover, | ||
child: FluentUI.TextButton( | ||
onPressed: onPressed, | ||
onLongPress: onLongPress, | ||
autofocus: autofocus, | ||
focusNode: focusNode, | ||
style: FluentUI.ButtonStyle( | ||
backgroundColor: | ||
Utils.resolveMaterialPropertyAsAllButtonState<Color?>( | ||
allStates, | ||
style?.backgroundColor, | ||
), | ||
elevation: Utils.resolveMaterialPropertyAsAllButtonState<double?>( | ||
allStates, | ||
style?.elevation, | ||
), | ||
foregroundColor: | ||
Utils.resolveMaterialPropertyAsAllButtonState<Color?>( | ||
allStates, | ||
style?.foregroundColor, | ||
), | ||
padding: Utils.resolveMaterialPropertyAsAllButtonState( | ||
allStates, | ||
style?.padding, | ||
), | ||
shadowColor: Utils.resolveMaterialPropertyAsAllButtonState<Color?>( | ||
allStates, | ||
style?.shadowColor, | ||
), | ||
textStyle: Utils.resolveMaterialPropertyAsAllButtonState( | ||
allStates, | ||
style?.textStyle, | ||
), | ||
shape: Utils.resolveMaterialPropertyAsAllButtonState( | ||
allStates, | ||
style?.shape, | ||
), | ||
border: Utils.resolveMaterialPropertyAsAllButtonState( | ||
allStates, | ||
style?.side, | ||
), | ||
), | ||
child: child, | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return getPlatformType(context); | ||
} | ||
} |