Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widgetIndicator issues #102

Closed
sefidgaran opened this issue Jan 14, 2021 · 9 comments
Closed

widgetIndicator issues #102

sefidgaran opened this issue Jan 14, 2021 · 9 comments

Comments

@sefidgaran
Copy link

Hello,

I am trying to add my widget as widgetIndicator in the LinearPercentIndicator widget but I see two issues:

1- In the first load after running the app it won't show my widgetIndicator and it just shown the animated line.

2- After loading the page for second time it will display my widgetIndicator but with wrong alignment, vertical alignment is not centered aligned with the line.

Note: my widgetIndicator is a statelessWidget including a Stack of three Image.asset .

Please advise.
Thanks

@diegoveloper
Copy link
Owner

Add minimum code to reproduce the issue

@sefidgaran
Copy link
Author

sefidgaran commented Jan 14, 2021

The sample code:

Expanded( child: Padding( padding: const EdgeInsets.only(left: 15.0, right: 35.0), child: Column( children: [ LinearPercentIndicator( padding: const EdgeInsets.all(0.0), isRTL: false, animation: true, lineHeight: 8.0, curve: Curves.fastOutSlowIn, animationDuration: 1000, percent: percentage / 100, progressColor: DefaultColorPalette.primaryAction, backgroundColor: Colors.white.withOpacity(0.10), linearStrokeCap: percentIndicator.LinearStrokeCap.roundAll, widgetIndicator: _myImagesWidget(), ), // Other widgets ])))

_myImagesWidget is statelesswidget including:
Image sizes are equaly width: 68, height: 26 in 1x

Widget build(BuildContext context) {
    return Stack(
      children: [
        Image.asset('image1.png'),
        Image.asset('image2.png'),
        Image.asset('image3.png'),
      ],
    );
  }

@diegoveloper
Copy link
Owner

Use code that I could run on my local. Minimum sample code.

@sefidgaran
Copy link
Author

sefidgaran commented Jan 14, 2021

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            LinearPercentIndicator(
              key: GlobalKey(),
              padding: const EdgeInsets.all(0.0),
              isRTL: false,
              animation: true,
              lineHeight: 8.0,
              curve: Curves.fastOutSlowIn,
              animationDuration: 1000,
              percent: 50 / 100,
              progressColor: Colors.green,
              backgroundColor: Colors.white.withOpacity(0.10),
              linearStrokeCap: LinearStrokeCap.roundAll,
              widgetIndicator: Image.asset('resources/images/greyhoundrunner_green.png'),
            ),
          ],
        ),
      ),
    );
  }
}

@sefidgaran
Copy link
Author

sefidgaran commented Jan 14, 2021

Hi @diegoveloper
Thanks for following up.

I created the sample code which you can see in previous post.

greyhoundrunner_green.png size is height: 26, width: 68 pixels in 1x resolution

greyhoundrunner_green

when you run the app at first the widgetIndicator (image) won't be displayed but if you hot reload you can see it is displayed but with wrong alignment.
Screenshots:

screenshot-1610597946665

1

@diegoveloper
Copy link
Owner

I tried using widgetIndicator: Icon(Icons.access_alarm), instead of your image and it works fine. Can you try with it?
What's the size of your image?

@sefidgaran
Copy link
Author

As I mentioned before the size of my image is height: 26, width: 68 pixels in 1x resolution, also I attached the image previously.
I tried using Icon the issue regarding displaying at first load is gone but the alignment has problem and its not centered.'

So, the issue is still there basically, It should b able to recieve any widget in widgetIndicator.

@aboo
Copy link

aboo commented Jan 15, 2021

I managed to solve the issue of indicator's location using the a container's transform like this:

   var indicator = Container(
      transform: Matrix4.translationValues(0, -6, 0),
      child: Icon(Icons.alarm_add_rounded),
    );

image

@sefidgaran
Copy link
Author

Thanks @aboo for the clue.

Solved the first time load image and image alignment issues by adding width, height and translation to the container as below:

var indicator = Container(
      width: 58,
      height: 24,
      transform: Matrix4.translationValues(0, -6, 0),
      child: Image.asset('resources/images/greyhoundrunner_green.png'),
    );

and then the usage in the LinearPercentIndicator would be like this:

LinearPercentIndicator(
              padding: const EdgeInsets.all(0.0),
              isRTL: false,
              animation: true,
              lineHeight: 8.0,
              curve: Curves.fastOutSlowIn,
              animationDuration: 1000,
              percent: 50 / 100,
              progressColor: Colors.green,
              backgroundColor: Colors.white.withOpacity(0.10),
              linearStrokeCap: LinearStrokeCap.roundAll,
              widgetIndicator: indicator,
            ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants