Last active
November 28, 2024 03:01
-
-
Save yeasin50/515dc4147d9737d1185f825f90d63b6f to your computer and use it in GitHub Desktop.
animate 3Sections [upwork]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
const MaterialApp( | |
home: HomePage(), | |
), | |
); | |
} | |
class HomePage extends StatefulWidget { | |
const HomePage({super.key}); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
int selectedIndex = 1; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: LayoutBuilder( | |
builder: (context, constraints) { | |
const fixedHeight = 100.0; | |
final expandHeight = constraints.maxHeight - fixedHeight; | |
return Column( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: [ | |
AnimatedContainer( | |
duration: Durations.medium1, | |
height: selectedIndex == 0 ? expandHeight : fixedHeight, | |
color: Colors.deepPurple, | |
child: Center( | |
child: ElevatedButton( | |
onPressed: () { | |
if (selectedIndex == 0) { | |
selectedIndex = 1; | |
} else { | |
selectedIndex = 0; | |
} | |
setState(() {}); | |
}, | |
child: Text(selectedIndex == 0 ? "Close" : "Expand"), | |
), | |
), | |
), | |
AnimatedContainer( | |
height: selectedIndex == 1 ? expandHeight - fixedHeight : 0, | |
duration: Durations.medium1, | |
color: Colors.red, | |
), | |
GestureDetector( | |
onTap: () { | |
if (selectedIndex == 2) { | |
selectedIndex = 1; | |
} else { | |
selectedIndex = 2; | |
} | |
setState(() {}); | |
}, | |
child: AnimatedContainer( | |
duration: Durations.medium1, | |
height: selectedIndex == 2 ? expandHeight : fixedHeight, | |
color: Colors.blue, | |
), | |
), | |
], | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment