Skip to content

Instantly share code, notes, and snippets.

@SankethBK
Created September 10, 2022 05:57
Show Gist options
  • Save SankethBK/4cd0557b3396caf4d979307df0008035 to your computer and use it in GitHub Desktop.
Save SankethBK/4cd0557b3396caf4d979307df0008035 to your computer and use it in GitHub Desktop.
Whatsapp profile page animation 3
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const WhatsappProfilePage());
}
}
class WhatsappProfilePage extends StatelessWidget {
const WhatsappProfilePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: CustomScrollView(
slivers: [
SliverPersistentHeader(
delegate: WhatsappAppbar(),
pinned: true,
),
SliverToBoxAdapter(
child: Column(
children: const [ProfileIconButtons()],
),
),
const WhatsappProfileBody()
],
),
),
);
}
}
class WhatsappAppbar extends SliverPersistentHeaderDelegate {
static final appBarColorTween = ColorTween(
begin: Colors.white, end: const Color.fromARGB(255, 4, 94, 84));
static final appbarIconColorTween =
ColorTween(begin: Colors.grey[800], end: Colors.white);
static final phoneNumberTranslateTween = Tween<double>(begin: 20.0, end: 0.0);
static final phoneNumberFontSizeTween = Tween<double>(begin: 20.0, end: 16.0);
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
final relativeScroll = min(shrinkOffset, 45) / 45;
final relativeScroll70px = min(shrinkOffset, 70) / 70;
return Container(
color: appBarColorTween.transform(relativeScroll),
child: Stack(
children: [
Stack(
children: [
Positioned(
left: 0,
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.arrow_back, size: 25),
color: appbarIconColorTween.transform(relativeScroll),
),
),
Positioned(
right: 0,
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.more_vert, size: 25),
color: appbarIconColorTween.transform(relativeScroll),
),
),
Positioned(
top: 15,
left: 90,
child: displayPhoneNumber(relativeScroll70px)),
],
),
],
),
);
}
Widget displayPhoneNumber(double relativeFullScrollOffset) {
if (relativeFullScrollOffset >= 0.8) {
return Transform(
transform: Matrix4.identity()
..translate(
0.0,
phoneNumberTranslateTween
.transform((relativeFullScrollOffset - 0.8) * 5),
),
child: Text(
"+3 3333333333",
style: TextStyle(
fontSize: phoneNumberFontSizeTween
.transform((relativeFullScrollOffset - 0.8) * 5),
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
);
}
return const SizedBox.shrink();
}
@override
double get maxExtent => 120;
@override
double get minExtent => 50;
@override
bool shouldRebuild(WhatsappAppbar oldDelegate) {
return true;
}
}
class WhatsappProfileBody extends StatelessWidget {
const WhatsappProfileBody({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SliverList(
delegate: SliverChildListDelegate(const [
SizedBox(height: 20),
ListTile(
title: Text("Custom Notifications"),
leading: Icon(Icons.notification_add),
),
ListTile(
title: Text("Disappearing messages"),
leading: Icon(Icons.message),
),
ListTile(
title: Text("Mute Notifications"),
leading: Icon(Icons.mic_off),
),
ListTile(
title: Text("Media visibility"),
leading: Icon(Icons.save),
),
// to fill up the rest of the space to enable scrolling
SizedBox(
height: 550,
),
]));
}
}
class ProfileIconButtons extends StatelessWidget {
const ProfileIconButtons({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: const [
Icon(
Icons.call,
size: 30,
color: Color.fromARGB(255, 8, 141, 125),
),
SizedBox(height: 5),
Text(
"Call",
style: TextStyle(
fontSize: 18,
color: Color.fromARGB(255, 8, 141, 125),
),
)
],
),
const SizedBox(width: 20),
Column(
children: const [
Icon(
Icons.video_call,
size: 30,
color: Color.fromARGB(255, 8, 141, 125),
),
SizedBox(height: 5),
Text(
"Video",
style: TextStyle(
fontSize: 18,
color: Color.fromARGB(255, 8, 141, 125),
),
)
],
),
const SizedBox(width: 20),
Column(
children: const [
Icon(
Icons.save,
size: 30,
color: Color.fromARGB(255, 8, 141, 125),
),
SizedBox(height: 5),
Text(
"Save",
style: TextStyle(
fontSize: 18,
color: Color.fromARGB(255, 8, 141, 125),
),
)
],
),
const SizedBox(width: 20),
Column(
children: const [
Icon(
Icons.search,
size: 30,
color: Color.fromARGB(255, 8, 141, 125),
),
SizedBox(height: 5),
Text(
"Search",
style: TextStyle(
fontSize: 18,
color: Color.fromARGB(255, 8, 141, 125),
),
)
],
),
],
);
}
}
class PhoneAndName extends StatelessWidget {
const PhoneAndName({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: const [
SizedBox(height: 35),
Text(
"+3 3333333333",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Text(
"~Walter Hartwell White",
style: TextStyle(
fontSize: 16,
),
),
SizedBox(height: 30),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment