Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material3 adaptation #72

Merged
merged 9 commits into from
Feb 26, 2024
11 changes: 10 additions & 1 deletion lib/src/buttons/circular_fab_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CircularFabWidget extends StatefulWidget {
final int _fwdAnimationDuration;
final int _revAnimationDuration;
final double? _radius;
final ShapeBorder? _shape;
///
const CircularFabWidget({
Key? key,
Expand All @@ -17,13 +18,15 @@ class CircularFabWidget extends StatefulWidget {
int fwdAnimationDuration = 120,
int revAnimationDuration = 50,
double? radius,
ShapeBorder? shape,
}) :
_icon = icon,
_children = children,
_buttonSize = buttonSize,
_fwdAnimationDuration = fwdAnimationDuration,
_revAnimationDuration = revAnimationDuration,
_radius = radius,
_shape = shape,
super(key: key);
//
@override
Expand All @@ -35,6 +38,7 @@ class CircularFabWidget extends StatefulWidget {
fwdAnimationDuration: _fwdAnimationDuration,
revAnimationDuration: _revAnimationDuration,
radius: _radius,
shape: _shape,
);
}

Expand All @@ -46,6 +50,7 @@ class _CircularFabWidgetState extends State<CircularFabWidget> with TickerProvid
final int _fwdAnimationDuration;
final int _revAnimationDuration;
final double? _radius;
final ShapeBorder? _shape;
late AnimationController _animationController;
///
_CircularFabWidgetState({
Expand All @@ -55,13 +60,15 @@ class _CircularFabWidgetState extends State<CircularFabWidget> with TickerProvid
required int fwdAnimationDuration,
required int revAnimationDuration,
double? radius,
ShapeBorder? shape,
}):
_icon = icon,
_children = children,
_buttonSize = buttonSize,
_fwdAnimationDuration = fwdAnimationDuration,
_revAnimationDuration = revAnimationDuration,
_radius = radius;
_radius = radius,
_shape = shape;
//
@override
void initState() {
Expand All @@ -76,6 +83,7 @@ class _CircularFabWidgetState extends State<CircularFabWidget> with TickerProvid
@override
Widget build(BuildContext context) {
final menuButton = FloatingActionButton(
shape: _shape,
key: UniqueKey(),
heroTag: UniqueKey(),
// elevation: 1.0,
Expand Down Expand Up @@ -170,6 +178,7 @@ class FlowMenuDelegate extends FlowDelegate {
? max(_animationController.value, 0.9)
: max(_animationController.value, 0.5),)
..translate(-_buttonSize / 2, -_buttonSize / 2),
opacity: isLastItem ? 1.0 : _animationController.value,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hmi_networking/hmi_networking.dart';
import 'package:hmi_core/hmi_core.dart';
import 'package:hmi_widgets/src/core/color_filters.dart';
import 'package:hmi_widgets/src/popups/popup_menu_button/popup_menu_button_custom.dart';
import 'package:hmi_widgets/hmi_widgets.dart';
///
/// Кнопка посылает значение bool / int / real в DsClient
class DropDownControlButton extends StatefulWidget {
Expand Down Expand Up @@ -154,7 +153,6 @@ class _DropDownControlButtonState extends State<DropDownControlButton> with Tick
Widget build(BuildContext context) {
final width = _width;
final height = _height;
final backgroundColor = Theme.of(context).colorScheme.primary;
final textColor = Theme.of(context).colorScheme.onPrimary;
return StreamBuilder<Null>(
stream: _streamController.stream,
Expand All @@ -164,41 +162,40 @@ class _DropDownControlButtonState extends State<DropDownControlButton> with Tick
_log.debug('[.build] _lastSelectedValue: $_lastSelectedValue');
_log.debug('[.build] isDisabled: $_isDisabled');
return PopupMenuButtonCustom<int>(
// color: backgroundColor,
offset: Offset(width != null ? width * 0.7 : 100, height ?? 0),
enabled: !_isDisabled,
tooltip: _tooltip,
child: Stack(
children: [
ColorFiltered(
colorFilter: ColorFilters.disabled(context, _isDisabled),
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(4.0),
),
width: _width,
height: _height,
child: AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return _buildButtonIcon(_lastSelectedValue, textColor, _animationController.value);
},
customButtonBuilder: (onTap) {
return Stack(
children: [
ColorFiltered(
colorFilter: ColorFilters.disabled(context, _isDisabled),
child: SizedBox(
width: _width,
height: _height,
child: ElevatedButton(
onPressed: onTap,
child: AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return _buildButtonIcon(_lastSelectedValue, textColor, _animationController.value);
},
),
),
),
),
),
if (_state.isLoading || _state.isSaving) Positioned.fill(
child: Container(
color: Theme.of(context).colorScheme.background.withOpacity(0.7),
alignment: Alignment.center,
child: CupertinoActivityIndicator(
color: Theme.of(context).colorScheme.onBackground,
if (_state.isLoading || _state.isSaving) Positioned.fill(
child: Container(
color: Theme.of(context).colorScheme.background.withOpacity(0.7),
alignment: Alignment.center,
child: CupertinoActivityIndicator(
color: Theme.of(context).colorScheme.onBackground,
),
),
),
),
],
),
],
);
},
itemBuilder: (context) {
return _items.map((index , item) {
return MapEntry(
Expand Down Expand Up @@ -257,16 +254,10 @@ class _DropDownControlButtonState extends State<DropDownControlButton> with Tick
scale: 1 - 0.2 * animationValue,
child: Transform.translate(
offset: Offset(0.0, - (Theme.of(context).textTheme.titleMedium?.fontSize ?? 18) * 0.07 * animationValue),
child: Text(
label,
style: Theme.of(context).textTheme.titleMedium?.apply(
color: color.withOpacity(1 - 0.2 * animationValue),
),
),
child: Text(label),
),
),
if (selectedItem != null) Center(

child: Text(
selectedItem,
style: Theme.of(context).textTheme.titleMedium!.apply(
Expand All @@ -276,20 +267,6 @@ class _DropDownControlButtonState extends State<DropDownControlButton> with Tick
),
],
);
// return Text(
// '${_items[value]}',
// style: Theme.of(context).textTheme.titleMedium!.copyWith(
// color: color,
// ),
// );
// }
// }
// return Text(
// '$_label',
// style: Theme.of(context).textTheme.titleMedium!.copyWith(
// color: color,
// ),
// );
}
///
void _sendValue(DsClient? dsClient, DsPointName? writeTagName, String? responseTagName, int? newValue) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/indicators/value_indicators/text_value_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _TextValueIndicatorState extends State<TextValueIndicator> {
Text(
value.toStringAsFixed(_fractionDigits),
style: _textStyle.apply(color: color),
textScaler: TextScaler.linear(1.5),
textScaler: TextScaler.linear(1.3),
),
..._buildUnitText(_valueUnit, color),
],
Expand All @@ -125,7 +125,7 @@ class _TextValueIndicatorState extends State<TextValueIndicator> {
Text(
_valueUnit,
style: _unitTextStyle.apply(color: color),
textScaler: TextScaler.linear(1.5),
textScaler: TextScaler.linear(1.3),
),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class PopupMenuButtonCustom<T> extends StatefulWidget {
this.elevation,
this.padding = const EdgeInsets.all(8.0),
this.child,
this.customButtonBuilder,
this.splashRadius,
this.icon,
this.iconSize,
Expand Down Expand Up @@ -117,6 +118,9 @@ class PopupMenuButtonCustom<T> extends StatefulWidget {
/// and the button will utilize an [InkWell] for taps.
final Widget? child;

///
final Widget Function(void Function()? onTap)? customButtonBuilder;

/// If provided, the [icon] is used for this button
/// and the button will behave like an [IconButton].
final Widget? icon;
Expand Down Expand Up @@ -287,6 +291,10 @@ class PopupMenuButtonCustomState<T> extends State<PopupMenuButtonCustom<T>> {
child: widget.child,
);
}
final builder = widget.customButtonBuilder;
if (builder != null) {
return builder(widget.enabled ? showButtonMenu : null);
}
return IconButton(
icon: widget.icon ?? Icon(Icons.adaptive.more),
padding: widget.padding,
Expand Down
24 changes: 24 additions & 0 deletions lib/src/theme/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ final Map<AppTheme, ThemeData> appThemes = {
///
/// Light theme of entire application
AppTheme.light: ThemeData(
typography: Typography.material2018(),
brightness: Brightness.light,
// scaffoldBackgroundColor: lightTheme.backgroundColor,
primaryColor: light_theme.primaryColor,
Expand Down Expand Up @@ -105,6 +106,12 @@ final Map<AppTheme, ThemeData> appThemes = {
tabBarTheme: TabBarTheme(
indicatorColor: light_theme.activeStateColor,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: light_theme.primaryColor,
foregroundColor: light_theme.onTertiary,
),
),
// elevatedButtonTheme: ElevatedButtonThemeData(
// style: ButtonStyle(
// elevation: MaterialStateProperty.all(cardThemeElevation),
Expand All @@ -119,10 +126,16 @@ final Map<AppTheme, ThemeData> appThemes = {
color: light_theme.tertiary,
textStyle: TextStyle(fontSize: 18, color: light_theme.onTertiary),
),
menuTheme: MenuThemeData(
style: MenuStyle(
backgroundColor: MaterialStateProperty.all(light_theme.primaryColor),
),
),
),
///
/// Dark theme of entire application
AppTheme.dark: ThemeData(
typography: Typography.material2018(),
brightness: Brightness.dark,
// scaffoldBackgroundColor: backgroundColor,
primaryColor: dark_theme.primaryColor,
Expand Down Expand Up @@ -155,6 +168,12 @@ final Map<AppTheme, ThemeData> appThemes = {
tabBarTheme: TabBarTheme(
indicatorColor: dark_theme.activeStateColor,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: dark_theme.primaryColor,
foregroundColor: dark_theme.onTertiary,
),
),
// elevatedButtonTheme: ElevatedButtonThemeData(
// style: ButtonStyle(
// // elevation: MaterialStateProperty.all(cardThemeElevation),
Expand All @@ -174,5 +193,10 @@ final Map<AppTheme, ThemeData> appThemes = {
color: dark_theme.primaryColor,
textStyle: TextStyle(fontSize: 18, color: dark_theme.onPrimary),
),
menuTheme: MenuThemeData(
style: MenuStyle(
backgroundColor: MaterialStateProperty.all(dark_theme.primaryColor),
),
),
),
};
Loading