-
Notifications
You must be signed in to change notification settings - Fork 22
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
10 changed files
with
329 additions
and
118 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 was deleted.
Oops, something went wrong.
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,4 @@ | ||
export 'widgets/button.dart'; | ||
export 'widgets/camera_stream.dart'; | ||
export 'widgets/joystick.dart'; | ||
export 'widgets/resources/base.dart'; |
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,146 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
|
||
enum ViamButtonRole { | ||
primary, | ||
inverse, | ||
success, | ||
danger, | ||
warning; | ||
|
||
Color get backgroundColor { | ||
final brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; | ||
final isDarkMode = brightness == Brightness.dark; | ||
switch (this) { | ||
case ViamButtonRole.primary: | ||
return isDarkMode ? const Color.fromARGB(255, 40, 40, 41) : const Color.fromARGB(255, 240, 240, 240); | ||
case ViamButtonRole.inverse: | ||
return isDarkMode ? const Color.fromARGB(255, 240, 240, 240) : const Color.fromARGB(255, 40, 40, 41); | ||
case ViamButtonRole.success: | ||
return isDarkMode ? const Color.fromARGB(255, 105, 153, 103) : const Color.fromARGB(255, 61, 125, 63); | ||
case ViamButtonRole.danger: | ||
return isDarkMode ? const Color.fromARGB(255, 211, 103, 94) : const Color.fromARGB(255, 190, 53, 54); | ||
case ViamButtonRole.warning: | ||
return isDarkMode ? const Color.fromARGB(255, 250, 185, 82) : const Color.fromARGB(255, 242, 166, 0); | ||
} | ||
} | ||
|
||
Color get foregroundColor { | ||
final brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; | ||
final isDarkMode = brightness == Brightness.dark; | ||
switch (this) { | ||
case ViamButtonRole.primary: | ||
return isDarkMode ? const Color.fromARGB(255, 240, 240, 240) : const Color.fromARGB(255, 40, 40, 41); | ||
case ViamButtonRole.inverse: | ||
return isDarkMode ? const Color.fromARGB(255, 40, 40, 41) : const Color.fromARGB(255, 240, 240, 240); | ||
case ViamButtonRole.success: | ||
return const Color.fromARGB(255, 255, 255, 255); | ||
case ViamButtonRole.danger: | ||
return const Color.fromARGB(255, 255, 255, 255); | ||
case ViamButtonRole.warning: | ||
return const Color.fromARGB(255, 255, 255, 255); | ||
} | ||
} | ||
|
||
MaterialColor get materialColor { | ||
switch (this) { | ||
case ViamButtonRole.primary: | ||
return Colors.grey; | ||
case ViamButtonRole.inverse: | ||
return Colors.grey; | ||
case ViamButtonRole.success: | ||
return Colors.green; | ||
case ViamButtonRole.danger: | ||
return Colors.red; | ||
case ViamButtonRole.warning: | ||
return Colors.amber; | ||
} | ||
} | ||
|
||
ButtonStyle get style => | ||
ButtonStyle(backgroundColor: MaterialStatePropertyAll(backgroundColor), foregroundColor: MaterialStatePropertyAll(foregroundColor)); | ||
} | ||
|
||
enum ViamButtonStyle { | ||
filled, | ||
outline, | ||
ghost; | ||
} | ||
|
||
enum ViamButtonVariant { | ||
iconOnly, | ||
iconLeading, | ||
iconTrailing; | ||
} | ||
|
||
class ViamButton extends StatelessWidget { | ||
final String text; | ||
final VoidCallback onPressed; | ||
final Widget? icon; | ||
final ViamButtonRole role; | ||
final ViamButtonStyle style; | ||
final ViamButtonVariant variant; | ||
|
||
const ViamButton( | ||
{required this.onPressed, | ||
required this.text, | ||
super.key, | ||
this.icon, | ||
this.role = ViamButtonRole.primary, | ||
this.style = ViamButtonStyle.filled, | ||
this.variant = ViamButtonVariant.iconLeading}); | ||
|
||
ButtonStyle get _buttonStyle { | ||
const mainStyle = ButtonStyle(splashFactory: NoSplash.splashFactory); | ||
|
||
if (style == ViamButtonStyle.ghost) { | ||
var fgColor = role.backgroundColor; | ||
if (role == ViamButtonRole.primary || role == ViamButtonRole.inverse) { | ||
fgColor = role.foregroundColor; | ||
} | ||
return mainStyle.copyWith( | ||
backgroundColor: const MaterialStatePropertyAll(Color.fromARGB(0, 0, 0, 0)), | ||
foregroundColor: MaterialStatePropertyAll(fgColor), | ||
); | ||
} | ||
if (style == ViamButtonStyle.outline) { | ||
var alpha = 25; | ||
var fgColor = role.backgroundColor; | ||
var outlineColor = role.backgroundColor; | ||
if (role == ViamButtonRole.primary || role == ViamButtonRole.inverse) { | ||
alpha = 0; | ||
fgColor = role.foregroundColor; | ||
outlineColor = role.foregroundColor; | ||
} | ||
return mainStyle.copyWith( | ||
backgroundColor: MaterialStatePropertyAll(role.backgroundColor.withAlpha(alpha)), | ||
foregroundColor: MaterialStatePropertyAll(fgColor), | ||
side: MaterialStatePropertyAll(BorderSide(color: outlineColor)), | ||
); | ||
} | ||
return mainStyle.copyWith( | ||
backgroundColor: MaterialStatePropertyAll(role.backgroundColor), | ||
foregroundColor: MaterialStatePropertyAll(role.foregroundColor), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
Widget child; | ||
if (icon != null) { | ||
if (variant == ViamButtonVariant.iconOnly) { | ||
child = IconButton(onPressed: onPressed, icon: icon!, style: _buttonStyle); | ||
} | ||
if (style == ViamButtonStyle.outline) { | ||
child = OutlinedButton.icon(onPressed: onPressed, icon: icon!, label: Text(text), style: _buttonStyle); | ||
} | ||
child = TextButton.icon(onPressed: onPressed, icon: icon!, label: Text(text), style: _buttonStyle); | ||
} | ||
if (style == ViamButtonStyle.outline) { | ||
child = OutlinedButton(onPressed: onPressed, style: _buttonStyle, child: Text(text)); | ||
} | ||
child = TextButton(onPressed: onPressed, style: _buttonStyle, child: Text(text)); | ||
|
||
return Theme(data: ThemeData(primarySwatch: role.materialColor), child: child); | ||
} | ||
} |
Oops, something went wrong.