شارك المقالة

اضافة تاثير على الصور في تصميم صفحات الويب باستخدام فلاتر


اضافة تاثير على الصور في تصميم صفحات الويب باستخدام فلاتر

عندما ترغب بعمل تاثير على الصور وخصوصا تحريك الصورة مع اظهار ظل عليها عند تحريك الماوس على الصورة المراده في flutter فالامر ليس بالصعب وسوف نشرح لكم في هذه المقال كيف تتم العمليه بكل بساطة والامر بسيط وسهل جدا ولن تحتاج الى اي مكاتب خارجية اطلاقا حتى تقوم بعمل التاثير لديك في مشروعك فقط كل الاكواد من داخل flutter نفسها حتى لا يحدث معك مشاكل في موقع الويب الذي تعمل عليه .


Add effect on image in Flutter project

الانميشن بكل بساطة يعتمد بشكل اساسي على معرفة موقع الماوس وهل تم وضع الماوس على الصورة ام لا وماهي الصورة التي وقع عليها الماوس وعند الحصول على هذه البيانات فورا يتم اظهار الانميشن عن طريق الاكواد الخاصه به كما هو موضح بالاكواد التاليه وتم فصل الكود حتى يظهر بشكل منسق وجميل كما هو موضح لدينا في الاسفل حتى تتمكن من نسخ الاكواد واستعمالها لديك بدون ادنى مشاكل وتحسن من شكل موقع الويب الذي تعمل عليه حتى يكون متناسق ويحتوي على انميشن لطيف .


Add effect on image in Flutter project

img.dart


class MyMobileBody extends StatefulWidget {
  const MyMobileBody({Key? key}) : super(key: key);

  @override
  State<MyMobileBody> createState() => _MyMobileBodyState();
}

class _MyMobileBodyState extends State<MyMobileBody> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      color: Colors.grey.shade200,
      child: Center(
        child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Icard(img: 'assets/img/background/image-4.jpg'),
                Icard(img: 'assets/img/background/image-5.png'),
                Icard(img: 'assets/img/background/image-3.jpg'),
                Icard(img: 'assets/img/background/image-1.png'),
              ],
            )
      ),
    ));
  }
}

class Icard extends StatefulWidget {
  final String img;
  const Icard({Key? key,required this.img}) : super(key: key);

  @override
  State<Icard> createState() => _IcardState();
}

class _IcardState extends State<Icard> {
  bool isHover = false;
  Offset mousPos = new Offset(0, 0);

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (e) {
        setState(() {
          isHover = true;
        });
      },
      onHover: (e) {
        setState(() {
          mousPos = Offset(e.delta.dx , e.delta.dy);
        });
      },
      onExit: (e) {
        setState(() {
          isHover = false;
        });
      },
      child: Container(
        height: 450,
        width: 280,
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Colors.grey.shade400,
              blurRadius: isHover ? 15 : 2,
              spreadRadius: isHover ? 5 : 2,
            ),
          ],
        ),
        child: Stack(
          children: [
            backImage(widget.img),
            // shadow animation .
            gradiant(),
            text(),
          ],
        ),
      ),
    );
  }

  backImage(String img) {
    return AnimatedPositioned(
      curve: Curves.easeOutCubic,
      duration: Duration(milliseconds: 1000),
      height: isHover ? 600 : 450,
      top: isHover ? -40 + mousPos.dy : 0,
      left: isHover ? -100 + mousPos.dx : -100,
      width: 500,
      child: Container(
        width: 500,
        height: 600,
        decoration: BoxDecoration(
          image: DecorationImage(
            fit: BoxFit.fitHeight,
            image: AssetImage(img)
          )
        ),
      ),
    );
  }

  gradiant() {
    return AnimatedContainer(
      duration: Duration(milliseconds: 1000),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.bottomCenter,
            end: Alignment.topRight,
            colors: [
              Colors.black.withOpacity(isHover ? 0.7 : 0),
              Colors.transparent,
            ]
        )
      ),
    );
  }

  text() {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: SizedBox(
        width: double.infinity,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            AnimatedDefaultTextStyle(child: Text('Test Image'), style: TextStyle(
              color: Colors.white.withOpacity(isHover ? 1 : 0.6),
              fontSize: 25
            ), duration: Duration(milliseconds: 1000)),
          ],
        ),
      ),
    );
  }
}
شاهد أيضًا
مقالات ذات صلة
تغير شكل الرسالة Toast الى اشكال رائعة في الاندرويد ستوديو | change Toast format message

  متابعي موقعنا الاعزاء مرحبا بكم في مقالة جديدة في برنامج android studio , في…

كيفية حفظ مشروع machine learning واستخدمه في المشاريع

كيفية حفظ مشروع machine learning واستخدمه في المشاريع في هذة المقالة سوف نتعرف على كيفية…

شرح كيفية عمل recyclerview داخل الاندرويد ستوديو بسهولة تامة

  متابعي موقعنا الاعزاء مرحبا بكم في مقالة جديدة في برنامج android studio حيث يتم…

🚫 مانع الإعلانات مفعل

يجب إيقاف مانع الإعلانات لاستكمال تصفح الموقع