![]() |
VOOZH | about |
In Flutter, the FractionalTranslation widget allows you to translate its child widget by a fraction of its own size along both the horizontal and vertical axes. In this article, we are going to implement the FractionalTranslation widget and explore some properties of it. A sample Image is given below to get an idea about what we are going to do in this article.
👁 Screenshot_2023-10-09-10-17-50-115_comexamplevideoplayer-(1)
FractionalTranslation(
translation: Offset(dx, dy),
child: YourChildWidget(),
)
To build this app, you need the following items installed on your machine:
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
First of all import material.dart file.
import 'package:flutter/material.dart';
Here the execution of our app starts.
In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.
In this class we are going to Implement the FractionalTranslation widget.The translation property of FractionalTranslation is set to Offset(0.8, 0.2), which means it will translate its child by 80% of the child's own width to the right and 20% of its own height down. Comments are added for better understanding.
FractionalTranslation(
translation: Offset(0.8, 0.2), // Translate by 80% of its width and 20% of its height
child: Container(
width: 100,
height: 100,
color: Colors.green, // Background color of the Container
child: Center(
child: Text(
'FractionalTranslation',
style: TextStyle(color: Colors.white), // Text color
),
),
),
),
👁 Screenshot_2023-10-09-10-17-50-115_comexamplevideoplayer-(1)