flutter_shimmer icon indicating copy to clipboard operation
flutter_shimmer copied to clipboard

Feature Request - adjust the width of the gradient and the angle

Open yuhao-nyc opened this issue 2 years ago • 1 comments

Screenshot 2023-09-20 at 11 54 05

Like in the screenshot. The gradient on the right is way wider than the gradient on the left (which used this shimmer package). Is there a way I can adjust how wide the gradient get? And on top of that can I adjust the tilt angle of the gradient?

yuhao-nyc avatar Sep 20 '23 15:09 yuhao-nyc

You can achieve that by using Shimmer constructor with the gradient field. The width might be controlled by stops and the angle by setting the correct alignment (begin and end). Here is a tilted narrow example:

import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            body: Center(
                child: Column(
      children: [
        const SizedBox(
          width: 200.0,
          height: 100.0,
          child: Shimmer(
            gradient: LinearGradient(
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
                colors: <Color>[
                  Colors.red,
                  Colors.red,
                  Colors.yellow,
                  Colors.red,
                  Colors.red,
                ],
                stops: <double>[
                  0.0,
                  0.48,
                  0.5,
                  0.52,
                  1.0
                ]),
            child: Text(
              'Shimmer',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 40.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
        SizedBox(
          width: 200.0,
          height: 100.0,
          child: Shimmer.fromColors(
            baseColor: Colors.red,
            highlightColor: Colors.yellow,
            child: const Text(
              'Shimmer',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 40.0,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ],
    ))));
  }
}

olexale avatar Feb 03 '24 12:02 olexale