Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
111 changes: 90 additions & 21 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:smarthomeui/util/smart_device_box.dart';
import 'package:animations/animations.dart'; // Add this import for animations

class HomePage extends StatefulWidget {
const HomePage({super.key});
const HomePage({Key? key}) : super(key: key);

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;

// padding constants
final double horizontalPadding = 40;
final double verticalPadding = 25;
Expand All @@ -30,6 +34,22 @@ class _HomePageState extends State<HomePage> {
});
}

@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 500),
);
_animationController.forward();
}

@override
void dispose() {
_animationController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -64,7 +84,7 @@ class _HomePageState extends State<HomePage> {
),
),

const SizedBox(height: 20),


// welcome home
Padding(
Expand All @@ -84,7 +104,7 @@ class _HomePageState extends State<HomePage> {
),
),

const SizedBox(height: 25),


const Padding(
padding: EdgeInsets.symmetric(horizontal: 40.0),
Expand All @@ -94,7 +114,7 @@ class _HomePageState extends State<HomePage> {
),
),

const SizedBox(height: 25),


// smart devices grid
Padding(
Expand All @@ -108,26 +128,51 @@ class _HomePageState extends State<HomePage> {
),
),
),
const SizedBox(height: 10),


// grid
Expanded(
child: GridView.builder(
itemCount: 4,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 25),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1 / 1.3,
child: ScaleTransition(
scale: CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
),
child: GridView.builder(
itemCount: 4,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 25),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1 / 1.3,
),
itemBuilder: (context, index) {
return RotationTransition(
turns: Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(
(0.5 / mySmartDevices.length) * index,
1.0,
curve: Curves.easeInOut,
),
),
),
child: FadeTransition(
opacity: _animationController,
child: FadeIn(
duration: Duration(milliseconds: 500),
child: SmartDeviceBox(
smartDeviceName: mySmartDevices[index][0],
iconPath: mySmartDevices[index][1],
powerOn: mySmartDevices[index][2],
onChanged: (value) =>
powerSwitchChanged(value, index),
),
),
),
);
},
),
itemBuilder: (context, index) {
return SmartDeviceBox(
smartDeviceName: mySmartDevices[index][0],
iconPath: mySmartDevices[index][1],
powerOn: mySmartDevices[index][2],
onChanged: (value) => powerSwitchChanged(value, index),
);
},
),
)
],
Expand All @@ -136,3 +181,27 @@ class _HomePageState extends State<HomePage> {
);
}
}
class FadeIn extends StatelessWidget {
final Widget child;
final Duration duration;

const FadeIn({
Key? key,
required this.child,
this.duration = const Duration(milliseconds: 300),
}) : super(key: key);

@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
duration: duration,
child: child,
transitionBuilder: (child, animation) {
return FadeTransition(
opacity: animation,
child: child,
);
},
);
}
}
Loading