🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / FLUTTER / Fancy background animations in Flutter süslü güzel animasyon kullanımı

1-) FLUTTER - Fancy background animations in Flutter süslü güzel animasyon kullanımı

 

EKRAN ÇIKTISI

 

 

1- flutter pub add supercharged

2- flutter pub add simple_animations

 

anim_bg_demo_page.dart

 

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';
import 'package:supercharged/supercharged.dart';

enum _ColorTween { color1, color2 }

class AnimBgDemoPage extends StatelessWidget {
  
@override
  
Widget build(BuildContext context) {
    
return Scaffold(
      appBar:
AppBar(
        title:
new Text("AnimBgDemoPage"),
      ),
      body:
Stack(
        children: <
Widget>[
          
Positioned.fill(child: AnimatedBackground()),
          onBottom(
AnimatedWave(
            height:
180,
            speed:
1.0,
          )),
          onBottom(
AnimatedWave(
            height:
120,
            speed:
0.9,
            offset:
pi,
          )),
          onBottom(
AnimatedWave(
            height:
220,
            speed:
1.2,
            offset:
pi / 2,
          )),
          
Positioned.fill(
              child:
new Center(
                child:
new Text(
                  
"GSY Flutter Demo",
                  style:
new TextStyle(
                      fontSize:
30,
                      fontWeight:
FontWeight.bold,
                      color:
Colors.white),
                ),
              )),
        ],
      ),
    );
  }

  
onBottom(Widget child) => Positioned.fill(
    child:
Align(
      alignment:
Alignment.bottomCenter,
      child: child,
    ),
  );
}

class AnimatedWave extends StatelessWidget {
  
final double? height;
  
final double? speed;
  
final double offset;

  
AnimatedWave({this.height, this.speed, this.offset = 0.0});

  
@override
  
Widget build(BuildContext context) {
    
return LayoutBuilder(builder: (context, constraints) {
      
return Container(
        height:
height,
        width: constraints.
biggest.width,
        child:
LoopAnimation<double>(
            duration: (
5000 / speed!).round().milliseconds,
            tween:
0.0.tweenTo(2 * pi),
            builder: (context, child, value) {
              
return CustomPaint(
                foregroundPainter:
CurvePainter(value + offset),
              );
            }),
      );
    });
  }
}

class CurvePainter extends CustomPainter {
  
final double value;

  
CurvePainter(this.value);

  
@override
  
void paint(Canvas canvas, Size size) {
    
final white = Paint()..color = Colors.white.withAlpha(60);
    
final path = Path();

    
final y1 = sin(value);
    
final y2 = sin(value + pi / 2);
    
final y3 = sin(value + pi);

    
final startPointY = size.height * (0.5 + 0.4 * y1);
    
final controlPointY = size.height * (0.5 + 0.4 * y2);
    
final endPointY = size.height * (0.5 + 0.4 * y3);

    
path.moveTo(size.width * 0, startPointY);
    
path.quadraticBezierTo(
        size.
width * 0.5, controlPointY, size.width, endPointY);
    
path.lineTo(size.width, size.height);
    
path.lineTo(0, size.height);
    
path.close();
    canvas.drawPath(
path, white);
  }

  
@override
  
bool shouldRepaint(CustomPainter oldDelegate) {
    
return true;
  }
}

class AnimatedBackground extends StatelessWidget {
  
@override
  
Widget build(BuildContext context) {
    
final tween = MultiTween<_ColorTween>()
      ..add(
        
_ColorTween.color1,
        
Color(0xffD38312).tweenTo(Colors.lightBlue.shade900),
        
3.seconds,
      )
      ..add(
        
_ColorTween.color2,
        
Color(0xffA83279).tweenTo(Colors.blue.shade600),
        
3.seconds,
      );

    
return MirrorAnimation<MultiTweenValues<_ColorTween>>(
      tween:
tween,
      duration:
tween.duration,
      builder: (context, child, value) {
        
return Container(
          decoration:
BoxDecoration(
              gradient:
LinearGradient(
                  begin:
Alignment.topCenter,
                  end:
Alignment.bottomCenter,
                  colors: [
                    value.get<
Color>(_ColorTween.color1),
                    value.get<
Color>(_ColorTween.color2)
                  ])),
        );
      },
    );
  }
}

 

 

KULLANIMI

 

@override
Widget build(BuildContext context) {
  
return  MaterialApp(
      home:
AnimBgDemoPage()
  );
}

 

 

 

kaynak : https://github.com/CarGuo/gsy_flutter_demo/blob/master/lib/widget/anim_bg_demo_page.dart

 

https://felixblaschke.medium.com/fancy-background-animations-in-flutter-4163d50f5c37

 

 2022 Şubat 28 Pazartesi
 399