mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-26 17:51:16 +00:00
refactor: split app wrapper from focused example code (multi-file apps)
Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap; a new lib/example.dart holds the full entry screen and focused example code, importing existing supporting files (screens/, tabs/, services/, models/, widgets/, utils/). Apps: analytics_integration, animation_example, biometrics, bottom_sheet, custom_home_drawer, google_signin, grid_layout, handling_routes, image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar, using_custom_fonts, using_listview, using_listwheelscrollview, using_platform_adaptive, view_pdf_file
This commit is contained in:
152
animation_example/lib/example.dart
Normal file
152
animation_example/lib/example.dart
Normal file
@@ -0,0 +1,152 @@
|
||||
// Example: A compass-like animation demo where tapping rotates a pen image
|
||||
// and points it toward a direction (north/west/south/east).
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Example extends StatefulWidget {
|
||||
const Example({super.key});
|
||||
|
||||
@override
|
||||
_ExampleState createState() => _ExampleState();
|
||||
}
|
||||
|
||||
class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
|
||||
late AnimationController controller;
|
||||
var target = 0.0;
|
||||
final Map<double, String> data = {
|
||||
0.25: "north",
|
||||
0.50: "west",
|
||||
0.75: "south",
|
||||
1.00: 'east'
|
||||
};
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 900),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
showResult(double target) {
|
||||
final snak = SnackBar(
|
||||
content: Text(
|
||||
"Pen is pointed to ${data[target]}",
|
||||
style: const TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w500, color: Colors.green),
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snak);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: SizedBox(
|
||||
width: double.infinity,
|
||||
height: size.height,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Positioned(
|
||||
top: 80,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(Colors.green)),
|
||||
child: const Text(
|
||||
"North",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white),
|
||||
))),
|
||||
Positioned(
|
||||
top: size.height * 0.48,
|
||||
left: -15,
|
||||
child: Transform.rotate(
|
||||
angle: 190.1,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
WidgetStateProperty.all(Colors.green)),
|
||||
child: const Text(
|
||||
"East",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white),
|
||||
)),
|
||||
)),
|
||||
Positioned(
|
||||
top: size.height * 0.48,
|
||||
right: -15,
|
||||
child: Transform.rotate(
|
||||
angle: -190.1,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
WidgetStateProperty.all(Colors.green)),
|
||||
child: const Text(
|
||||
"West",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white),
|
||||
)),
|
||||
)),
|
||||
Positioned(
|
||||
bottom: 80,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(Colors.green)),
|
||||
child: const Text(
|
||||
"North",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white),
|
||||
))),
|
||||
AnimatedBuilder(
|
||||
animation: controller,
|
||||
child: Container(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
controller.repeat();
|
||||
});
|
||||
Future.delayed(Duration(seconds: 10), () {
|
||||
setState(() {
|
||||
target += 0.25;
|
||||
controller.animateTo(target,
|
||||
duration: Duration(seconds: 1));
|
||||
showResult(target);
|
||||
if (target == 1.00) {
|
||||
target = 0.0;
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
child: Image.asset(
|
||||
'assets/images/penimg2.png',
|
||||
width: size.width * 0.5,
|
||||
)),
|
||||
),
|
||||
builder: (context, Widget? widget) {
|
||||
return Transform.rotate(
|
||||
angle: controller.value * 2 * 3.14,
|
||||
child: widget,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user