1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2026-08-25 01:05:36 +00:00
Files
flutter-examples/animation_example/lib/home_page.dart
Nishant Srivastava 5c53498119 refactor: standardize Dart and Android config across all 54 apps
- Bump all apps to sdk >=3.0.0 <4.0.0 and add flutter_lints + a shared
  analysis_options.yaml to every app (flutter analyze is now green repo-wide)
- Fix real compile errors in firebase_google_authentication and image_editor,
  plus deprecated APIs (Matrix4, SvgPicture.color, textScaleFactor),
  missing async 'mounted' guards, and misc lints via dart fix + manual fixes
- Align pubspec 'name' with each folder and Android namespace/applicationId
  with the documented github.nisrulz.* convention
- Convert bmi_calculator from a legacy Flutter module to a standard app
  with a proper android/ scaffold; fix missing android:exported in launcher
  manifests across 22 apps so all Android builds pass
- Untrack generated build files (GeneratedPluginRegistrant,
  .flutter-plugins-dependencies) and ignore them
2026-08-17 17:26:39 +02:00

154 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
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,
);
},
),
],
),
),
);
}
}