Home > database >  Transition with futter move object
Transition with futter move object

Time:02-10

how i can move my object with transform for start position object to a X position value i tried this code but not work

                  new Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
       for(var i = 0; i > 0;i  )
      {
      
        Transform.translate(
          child: Text(
              'Woolha.com',
              style: TextStyle(color: Colors.teal, fontSize: 20)
          ),
          offset: Offset(
             i
            ,
              0),
        )
      }
],
                  ),

CodePudding user response:

you cant use for() method inside the widgets tree insted you can use that code but im not recommend it

  import 'package:flutter/material.dart';

class DashBoardScreen extends StatefulWidget {
  @override
  _DashBoardScreenState createState() => _DashBoardScreenState();
}

class _DashBoardScreenState extends State<DashBoardScreen> {

  double a = 0 ;

  _startMoving(){
    for(double i = 0; i <=250;i  ){
      
      setState(() {
        a = i;
       
      });
    }

  }





  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
                  Transform.translate(
                    child: Text(
                        'Woolha.com ? what this',
                        style: TextStyle(color: Colors.teal, fontSize: 20)
                    ),

                    offset: Offset(
                        a
                        ,
                        0),
                  )
            ],

          ),
        ElevatedButton(onPressed: ()=> _startMoving(), child: Icon(Icons.arrow_forward))

        ],
      ),
    );
  }
}

i recommend you to use AnimatedPositioned

CodePudding user response:

thank you ♥ question please, if you not recommand this method so how i can make movig an object with AnimatedPositioned ? if i want an object move with a value = 1, or a value = 10

or something like that:

i = 0;
i  ;

or

i = 0;

i = i   10;

how i can do that with AnimatedPositioned

  • Related