0

I'm following this speed code tutorial(https://www.youtube.com/watch?v=KO_PYJKHglo) and I'm facing some problems during somewhere on 6:04.

I did some typing ! and ? for any null safety related problems but nothing had changed.

import 'package:flutter/material.dart';
import 'package:secondlife_mobile/clipper.dart';
import 'package:secondlife_mobile/wave_base_painter.dart';
import 'package:secondlife_mobile/wave_color_painter.dart';

void main() {
  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: PlayerApp(),
    ),
  );
}

class PlayerApp extends StatefulWidget {
  const PlayerApp({super.key});

  @override
  State<PlayerApp> createState() => _PlayerAppState();
}

class _PlayerAppState extends State<PlayerApp> with TickerProviderStateMixin {
  AnimationController? _controller;
  Animation? _waveAnim;
  Animation? _waveConstAmpAnim;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: const Duration(seconds: 20))
          ..addListener(() => setState(() {}));
    _waveAnim = Tween<double>(begin: 1, end: 1).animate(_controller);
    _waveConstAmpAnim = Tween<double>(begin: 0, end: 1).animate(
        CurvedAnimation(curve: Curves.easeInSine, parent: _controller));
    _controller!.forward(); //null safe 6:32
  }

  @override
  Widget build(BuildContext context) {
    final height = MediaQuery.of(context).size.height;
    final width = MediaQuery.of(context).size.width;
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Positioned(
            height: height,
            width: width,
            child: Material(
              elevation: 16,
              color: const Color(0xFFd6dde5), //Background Color
              borderRadius: BorderRadius.circular(20),
              child: Padding(
                padding: const EdgeInsets.symmetric(
                  horizontal: 30.0,
                ),
                child: Column(
                  children: <Widget>[
                    const SizedBox(
                      height: 90,
                    ),
                    const Text(
                      'Music title',
                    ),
                    const SizedBox(
                      height: 15,
                    ),
                    const Text(
                      'Music artist',
                    ),
                    const SizedBox(
                      height: 75,
                    ),
                    buildRecordPlayer(),
                    const SizedBox(
                      height: 60,
                    ),
                    Row(
                      children: <Widget>[
                        const Text('time'),
                        const SizedBox(
                          width: 8,
                        ),
                        buildWave(width),
                        const SizedBox(
                          width: 8,
                        ),
                        const Text('end'),
                      ],
                    )
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget buildRecordPlayer() {
    return Container(
      height: 270,
      width: 270,
      alignment: Alignment.center,
      decoration: const BoxDecoration(
        image: DecorationImage(
          image: AssetImage('assets/images/vinyl.png'),
          fit: BoxFit.fitHeight,
          colorFilter: ColorFilter.mode(
            Colors.blue,
            BlendMode.color,
          ),
        ),
        shape: BoxShape.circle,
      ),
      child: ClipOval(
        child: Image.asset(
          'assets/images/SL.png',
          height: 165,
          width: 165,
          fit: BoxFit.fill,
        ),
      ),
    );
  }

  Widget buildWave(double width) {
    return SizedBox(
      width: 260 * _waveAnim.value,
      height: 40,
      child: CustomPaint(
        painter: WaveBasePainter(),
        child: ClipRect(
          clipper: WaveClipper(_waveConstAmpAnim.value * width),
          child: CustomPaint(
            painter: WaveBasePainter(),
            foregroundPainter: WaveColorPainter(_waveAnim),
          ),
        ),
      ),
    );
  }
}

And this is how my vscode looks like right now. I would be grateful if I could get rid of this error.

result

loupdaniel
  • 47
  • 1
  • 7

0 Answers0