flutter_box_transform 0.4.3 flutter_box_transform: ^0.4.3 copied to clipboard
A Flutter implementation of box_transform package that provides easy 2D box transform operations with advanced resizing of rect in UI.
import 'package:flutter/material.dart';
import 'package:flutter_box_transform/flutter_box_transform.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Box Transform Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late Rect rect = Rect.fromCenter(
center: MediaQuery.of(context).size.center(Offset.zero),
width: 400,
height: 300,
);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
TransformableBox(
rect: rect,
clampingRect: Offset.zero & MediaQuery.sizeOf(context),
onChanged: (result, event) {
setState(() {
rect = result.rect;
});
},
contentBuilder: (context, rect, flip) {
return DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.primary,
),
image: const DecorationImage(
image: AssetImage('assets/image1.png'),
fit: BoxFit.fill,
),
),
);
},
),
],
),
);
}
}