Skip to content

Instantly share code, notes, and snippets.

View mohak1283's full-sized avatar
🎯
Focusing

Mohak Gupta mohak1283

🎯
Focusing
View GitHub Profile
name: custom_switch
description: Beautiful Custom Switch created with Flutter.
version: 0.0.1
author: Mohak Gupta <mohak1283@gmail.com>
homepage: https://github.com/mohak1283/CustomSwitch
import 'package:custom_switch/custom_switch.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
custom_switch:
path: ../
onTap: () {
if (_animationController.isCompleted) {
_animationController.reverse();
} else {
_animationController.forward();
}
widget.value == false
? widget.onChanged(true)
: widget.onChanged(false);
},
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return Container(
width: 70.0,
height: 35.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
Animation _circleAnimation;
AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 60));
_circleAnimation = AlignmentTween(
library custom_switch;
import 'package:flutter/material.dart';
class CustomSwitch extends StatefulWidget {
final bool value;
final ValueChanged<bool> onChanged;
final Color activeColor;
const CustomSwitch({Key key, this.value, this.onChanged, this.activeColor})
@override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar(
title: Text('Animated Screen'),
),
body: Center(
child: AnimatedBuilder(
class AnimatedScreen extends StatefulWidget {
@override
_AnimatedScreenState createState() => _AnimatedScreenState();
}
class _AnimatedScreenState extends State<AnimatedScreen>
with TickerProviderStateMixin {
Animation _containerRadiusAnimation,
_containerSizeAnimation,
_containerColorAnimation;
@override
void dispose() {
super.dispose();
_arrowAnimationController?.dispose();
_heartAnimationController?.dispose();
}