how to user Analog Clock in Flutter App?
first create flutter project using
flutter create analog_clock
now import package from pubdev
open your pubspec.yaml file
animated_analog_clock: ^0.0.2
you can use directly in your mian/home page
create new file in your lib folder home.dart
main.dart
import 'package:analog_clock/home.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
home.dart
with graditent background
import 'package:animated_analog_clock/animated_analog_clock.dart';
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Analog Clock"),
),
body: const Center(
child: AnimatedAnalogClock(
location: 'Australia/Darwin',
// Gradient Background if you want
backgroundGradient:
RadialGradient(colors: [Colors.amberAccent, Colors.green]),
backgroundColor: Color(0xff1E1E26),
hourHandColor: Colors.lightBlueAccent,
minuteHandColor: Colors.lightBlueAccent,
secondHandColor: Colors.amber,
centerDotColor: Colors.amber,
hourIndicatorColor: Colors.lightBlue,
minuteIndicatorColor: Colors.blueAccent,
),
),
);
}
}
without Gradient Background
import 'package:animated_analog_clock/animated_analog_clock.dart';
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Analog Clock"),
),
body: const Center(
child: AnimatedAnalogClock(
location: 'Australia/Darwin',
backgroundColor: Color(0xff1E1E26),
hourHandColor: Colors.lightBlueAccent,
minuteHandColor: Colors.lightBlueAccent,
secondHandColor: Colors.amber,
centerDotColor: Colors.amber,
hourIndicatorColor: Colors.lightBlue,
minuteIndicatorColor: Colors.blueAccent,
),
),
);
}
}
Screenshot: