Skip to content

Commit 3b719dd

Browse files
SaadArdatiBirjuVachhani
authored andcommitted
🪄 Create minimal example.
1 parent 54635bf commit 3b719dd

File tree

3 files changed

+34
-96
lines changed

3 files changed

+34
-96
lines changed

.run/Example.run.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 33 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_box_transform/flutter_box_transform.dart';
23

34
void main() {
45
runApp(const MyApp());
@@ -7,119 +8,62 @@ void main() {
78
class MyApp extends StatelessWidget {
89
const MyApp({super.key});
910

10-
// This widget is the root of your application.
1111
@override
1212
Widget build(BuildContext context) {
1313
return MaterialApp(
14-
title: 'Flutter Demo',
14+
title: 'Box Transform Demo',
1515
theme: ThemeData(
16-
// This is the theme of your application.
17-
//
18-
// TRY THIS: Try running your application with "flutter run". You'll see
19-
// the application has a blue toolbar. Then, without quitting the app,
20-
// try changing the seedColor in the colorScheme below to Colors.green
21-
// and then invoke "hot reload" (save your changes or press the "hot
22-
// reload" button in a Flutter-supported IDE, or press "r" if you used
23-
// the command line to start the app).
24-
//
25-
// Notice that the counter didn't reset back to zero; the application
26-
// state is not lost during the reload. To reset the state, use hot
27-
// restart instead.
28-
//
29-
// This works for code too, not just values: Most code changes can be
30-
// tested with just a hot reload.
3116
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
3217
useMaterial3: true,
3318
),
34-
home: const MyHomePage(title: 'Flutter Demo Home Page'),
19+
home: const MyHomePage(),
3520
);
3621
}
3722
}
3823

3924
class MyHomePage extends StatefulWidget {
40-
const MyHomePage({super.key, required this.title});
41-
42-
// This widget is the home page of your application. It is stateful, meaning
43-
// that it has a State object (defined below) that contains fields that affect
44-
// how it looks.
45-
46-
// This class is the configuration for the state. It holds the values (in this
47-
// case the title) provided by the parent (in this case the App widget) and
48-
// used by the build method of the State. Fields in a Widget subclass are
49-
// always marked "final".
50-
51-
final String title;
25+
const MyHomePage({super.key});
5226

5327
@override
5428
State<MyHomePage> createState() => _MyHomePageState();
5529
}
5630

5731
class _MyHomePageState extends State<MyHomePage> {
58-
int _counter = 0;
32+
late Rect rect = Rect.fromCenter(
33+
center: MediaQuery.of(context).size.center(Offset.zero),
34+
width: 200,
35+
height: 200,
36+
);
5937

60-
void _incrementCounter() {
61-
setState(() {
62-
// This call to setState tells the Flutter framework that something has
63-
// changed in this State, which causes it to rerun the build method below
64-
// so that the display can reflect the updated values. If we changed
65-
// _counter without calling setState(), then the build method would not be
66-
// called again, and so nothing would appear to happen.
67-
_counter++;
68-
});
69-
}
38+
late Rect clampingRect = (Offset.zero & MediaQuery.of(context).size);
7039

7140
@override
7241
Widget build(BuildContext context) {
73-
// This method is rerun every time setState is called, for instance as done
74-
// by the _incrementCounter method above.
75-
//
76-
// The Flutter framework has been optimized to make rerunning build methods
77-
// fast, so that you can just rebuild anything that needs updating rather
78-
// than having to individually change instances of widgets.
7942
return Scaffold(
80-
appBar: AppBar(
81-
// TRY THIS: Try changing the color here to a specific color (to
82-
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
83-
// change color while the other colors stay the same.
84-
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
85-
// Here we take the value from the MyHomePage object that was created by
86-
// the App.build method, and use it to set our appbar title.
87-
title: Text(widget.title),
88-
),
89-
body: Center(
90-
// Center is a layout widget. It takes a single child and positions it
91-
// in the middle of the parent.
92-
child: Column(
93-
// Column is also a layout widget. It takes a list of children and
94-
// arranges them vertically. By default, it sizes itself to fit its
95-
// children horizontally, and tries to be as tall as its parent.
96-
//
97-
// Column has various properties to control how it sizes itself and
98-
// how it positions its children. Here we use mainAxisAlignment to
99-
// center the children vertically; the main axis here is the vertical
100-
// axis because Columns are vertical (the cross axis would be
101-
// horizontal).
102-
//
103-
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
104-
// action in the IDE, or press "p" in the console), to see the
105-
// wireframe for each widget.
106-
mainAxisAlignment: MainAxisAlignment.center,
107-
children: <Widget>[
108-
const Text(
109-
'You have pushed the button this many times:',
110-
),
111-
Text(
112-
'$_counter',
113-
style: Theme.of(context).textTheme.headlineMedium,
114-
),
115-
],
116-
),
43+
body: Stack(
44+
fit: StackFit.expand,
45+
children: [
46+
TransformableBox(
47+
rect: rect,
48+
clampingRect: clampingRect,
49+
onChanged: (result, event) {
50+
setState(() {
51+
rect = result.rect;
52+
});
53+
},
54+
contentBuilder: (context, rect, flip) {
55+
return const DecoratedBox(
56+
decoration: BoxDecoration(
57+
gradient: LinearGradient(
58+
colors: [Colors.red, Colors.blue],
59+
),
60+
),
61+
child: Placeholder(),
62+
);
63+
},
64+
),
65+
],
11766
),
118-
floatingActionButton: FloatingActionButton(
119-
onPressed: _incrementCounter,
120-
tooltip: 'Increment',
121-
child: const Icon(Icons.add),
122-
), // This trailing comma makes auto-formatting nicer for build methods.
12367
);
12468
}
12569
}

packages/flutter_box_transform/playground/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MyApp extends StatelessWidget {
6060
),
6161
initial: AdaptiveThemeMode.system,
6262
builder: (theme, darkTheme) => MaterialApp(
63-
title: 'Box Transform demo',
63+
title: 'Box Transform Playground',
6464
debugShowCheckedModeBanner: false,
6565
theme: theme,
6666
darkTheme: darkTheme,

0 commit comments

Comments
 (0)