Flutter imitates Netease cloud music: play the interface, and you can find a job after reading it

Posted by gtrufitt on Sun, 21 Nov 2021 02:26:09 +0100

[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-xxv5rz2b-1631251709878)( https://user-gold-cdn.xitu.io/2019/1/8/1682c515f06f92b1?imageslim )]

thinking

This interface is actually relatively simple to implement, which can be roughly divided into the following parts:

  • 1. Gaussian Blur effect of background
  • 2. Rotating animation of black glue cartridge
  • 3. Rotating animation of vinyl record
  • 4. Lower controller and progress bar

Let's talk about the implementation process one by one.

practice

The whole interface is a stacked view. At the bottom is a background picture, which is covered with a Gaussian fuzzy translucent mask, and then the upper layer is the title, vinyl player and controller.

1. Background Gaussian blur

Firstly, the stack component is used to wrap the stacked view. There are two container s in it. The first is a background network picture and the second is a BackdropFilter.

Stack(
      children: <Widget>[
        new Container(
          decoration: new BoxDecoration(
            image: new DecorationImage(
              image: new NetworkImage(coverArt),
              fit: BoxFit.cover,
              colorFilter: new ColorFilter.mode(
                Colors.black54,
                BlendMode.overlay,
              ),
            ),
          ),
        ),
        new Container(
            child: new BackdropFilter(
          filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
          child: Opacity(
            opacity: 0.6,
            child: new Container(
              decoration: new BoxDecoration(
                color: Colors.grey.shade900,
              ),
            ),
          ),
        )),
        
        ...
    ] 

Here, the values of Gaussian blur sigma X and sigma y are 10, then the transparency is 0.6 and the color is grey.shade900.

2. Rotating animation of black glue cartridge

The knowledge of animation will not be introduced in detail here. You can refer to the official document [portal](

)

The custom animation components are in the need_anim.dart file. Here, the animation and components are decoupled, and the animation process class PivotTransition is defined respectively. As the name suggests, it rotates around a fulcrum and inherits from the AnimatedWidget.

The fulcrum is set at the topcenter of the child component. Note that turns cannot be empty. You need to calculate the circumference of the rotation bypass according to the value of turns and rotate around the Z axis.

class PivotTransition extends AnimatedWidget {
  ///Create rotation transform
  ///turns cannot be empty
  PivotTransition({
    Key key,
    this.alignment: FractionalOffset.topCenter,
    @required Animation<double> turns,
    this.child,
  }) : super(key: key, listenable: turns);

  /// The animation that controls the rotation of the child.
  /// If the current value of the turns animation is v, the child will be
  /// rotated v * 2 * pi radians before being painted.
  Animation<double> get turns => listenable;

  /// The pivot point to rotate around.
  final FractionalOffset alignment;

  /// The widget below this widget in the tree.
  final Widget child;

  @override
  Widget build(BuildContext context) {
    final double turnsValue = turns.value;
    final Matrix4 transform = new Matrix4.rotationZ(turnsValue * pi * 2.0);
    return new Transform(
      transform: transform,
      alignment: alignment,
      child: child,
    );
  }
} 

The next step is to customize the black glue cartridge assembly.

final _rotateTween = new Tween<double>(begin: -0.15, end: 0.0);
new Container(
  child: new PivotTransition(
    turns: _rotateTween.animate(controller_needle),
    alignment: FractionalOffset.topLeft,
    child: new Container(
      width: 100.0,
      child: new Image.asset("images/play_needle.png"),
    ),
  ),
), 

Wrap the png picture in the container and pass it to PivotTransition as a child parameter.

When used externally, a Tween is passed in, starting at -0.15 ~ 0.0.

3. Rotating animation of vinyl record

This part of the code is in the record_anim.dart file. The RotationTransition provided by package: Shuttle / animation.dart is used for rotation, which is very simple.

class RotateRecord extends AnimatedWidget {
  RotateRecord({Key key, Animation<double> animation})
      : super(key: key, listenable: animation);

  Widget build(BuildContext context) {


# summary

Android Advanced architecture learning is a long and arduous road. It can't be learned by passion or by staying up for a few days and nights. We must develop the habit of studying hard at ordinary times.**So: insist!**

The analysis of the company's real interview questions in 2020 shared above. The author also sorted out the main interview technical points of front-line Internet enterprises into videos and PDF(In fact, it takes a lot more energy than expected), including the context of knowledge + Many details.

**[CodeChina Open source projects:< Android Summary of study notes+Mobile architecture video+Real interview questions for large factories+Project practice source code](

)**

**Just write this first. The code word is not easy. It is very one-sided. Please point out the disadvantages. If you think it has reference value, you can also pay attention to me**


> **①「Android Analysis of real interview questions」PDF Full HD version+②「Android Interview knowledge system」Learning mind map compressed package reading and downloading**,Finally, friends who feel helpful and in need can praise them
>
> ![](https://img-blog.csdnimg.cn/img_convert/e4c9fdae71d444486fd9d33281690863.png)
>
> ![](https://img-blog.csdnimg.cn/img_convert/88de6dda675d9bd4efa10b23db570a1a.png)
>
> ![](https://img-blog.csdnimg.cn/img_convert/4c4e018ae31fd82c40b111360f332e76.png)



> **This article has been[tencent CODING Open source hosting project:< Android Summary of study notes+Mobile architecture video+Real interview questions for large factories+Project practice source code](https://ali1024.coding.net/public/P7/Android/git), self-study resources and series of articles are constantly updated**
F-1631251709883)]



> **This article has been[tencent CODING Open source hosting project:< Android Summary of study notes+Mobile architecture video+Real interview questions for large factories+Project practice source code](https://ali1024.coding.net/public/P7/Android/git), self-study resources and series of articles are constantly updated**

Topics: Design Pattern Programmer Flutter