Skip to content
Snippets Groups Projects
Select Git revision
  • c53f6e39be9f9567b7dd406cf96bf3f9d207e5d1
  • master default protected
  • 39-upgrade-framework-and-dependencies
  • 22-improve-app-metadata
  • 9-improve-layout-and-graphics
  • Release_0.9.0_34 protected
  • Release_0.8.2_33 protected
  • Release_0.8.1_32 protected
  • Release_0.8.0_31 protected
  • Release_0.7.0_30 protected
  • Release_0.6.0_29 protected
  • Release_0.5.0_28 protected
  • Release_0.4.2_27 protected
  • Release_0.4.1_26 protected
  • Release_0.4.0_25 protected
  • Release_0.3.1_24 protected
  • Release_0.3.0_23 protected
  • Release_0.2.1_22 protected
  • Release_0.2.0_21 protected
  • Release_0.1.1_20 protected
  • Release_0.1.0_19 protected
  • Release_0.0.18_18 protected
  • Release_0.0.17_17 protected
  • Release_0.0.16_16 protected
  • Release_0.0.15_15 protected
25 results

global_app_bar.dart

Blame
  • parameter_painter.dart 1.69 KiB
    import 'dart:math';
    
    import 'package:flutter/material.dart';
    import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
    
    import 'package:tetrisdual/models/settings/settings_activity.dart';
    import 'package:tetrisdual/models/settings/settings_global.dart';
    
    class ParameterPainter extends CustomPainter {
      const ParameterPainter({
        required this.code,
        required this.value,
        required this.activitySettings,
        required this.globalSettings,
      });
    
      final String code;
      final String value;
      final ActivitySettings activitySettings;
      final GlobalSettings globalSettings;
    
      @override
      void paint(Canvas canvas, Size size) {
        // force square
        final double canvasSize = min(size.width, size.height);
    
        // content
        switch (code) {
          default:
            printlog('Unknown parameter: $code/$value');
            paintUnknownParameterItem(canvas, canvasSize);
        }
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    
      // "unknown" parameter -> simple block with text
      void paintUnknownParameterItem(
        final Canvas canvas,
        final double size,
      ) {
        final paint = Paint();
        paint.strokeJoin = StrokeJoin.round;
        paint.strokeWidth = 3;
    
        final textSpan = TextSpan(
          text: '$code\n$value',
          style: const TextStyle(
            color: Colors.black,
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        );
        final textPainter = TextPainter(
          text: textSpan,
          textDirection: TextDirection.ltr,
          textAlign: TextAlign.center,
        );
        textPainter.layout();
        textPainter.paint(
          canvas,
          Offset(
            (size - textPainter.width) * 0.5,
            (size - textPainter.height) * 0.5,
          ),
        );
      }