Skip to content
Snippets Groups Projects
parameter_widget.dart 1.73 KiB
Newer Older
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';

import 'package:reversi/models/settings/settings_activity.dart';
import 'package:reversi/models/settings/settings_global.dart';

class ParameterWidget extends StatelessWidget {
  const ParameterWidget({
    super.key,
    required this.code,
    required this.value,
    required this.isSelected,
    required this.size,
    required this.activitySettings,
    required this.globalSettings,
    required this.onPressed,
  });

  final String code;
  final String value;
  final bool isSelected;
  final double size;
  final ActivitySettings activitySettings;
  final GlobalSettings globalSettings;
  final VoidCallback onPressed;

  static const Color buttonColorActive = Colors.blue;
  static const Color buttonColorInactive = Colors.white;
  static const double buttonBorderWidth = 4.0;
  static const double buttonBorderRadius = 12.0;

  @override
  Widget build(BuildContext context) {
    Widget content = const SizedBox.shrink();

    switch (code) {
      default:
        printlog('Unknown parameter: $code/$value');
        content = getUnknownParameterItem();
    }

    final Color buttonColor = isSelected ? buttonColorActive : buttonColorInactive;

    return Container(
      decoration: BoxDecoration(
        color: buttonColor,
        borderRadius: BorderRadius.circular(buttonBorderRadius),
        border: Border.all(
          color: buttonColor,
          width: buttonBorderWidth,
        ),
      ),
      child: content,
    );
  }

  // "unknown" parameter -> simple block with text
  Widget getUnknownParameterItem() {
    return StyledButton.text(
      caption: '$code / $value',
      color: Colors.grey,
      onPressed: null,
    );
  }
}