Last active
July 7, 2020 19:22
-
-
Save yacineblr/678733a95c426621887781752f57675e to your computer and use it in GitHub Desktop.
How to play with the red box
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'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: TestView(), | |
), | |
); | |
} | |
} | |
final greenBigBox = Container(height: 700, color: Colors.green); | |
final yellowLitleBox = Container(height: 200, color: Colors.yellow); | |
class TestView extends StatefulWidget { | |
@override | |
_TestViewState createState() => _TestViewState(); | |
} | |
class _TestViewState extends State<TestView> { | |
List<Widget> _switchers = [greenBigBox, yellowLitleBox]; | |
int _currentWidget = 0; | |
int _counter = 0; | |
nextStep() { | |
if (_currentWidget > _switchers.length) { | |
return; | |
} | |
setState(() => ++_currentWidget); | |
} | |
previousStep() { | |
if (_currentWidget == 0) { | |
return; | |
} | |
setState(() => --_currentWidget); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Stack(children: [ | |
Positioned.fill( | |
child: GestureDetector( | |
onTap: () => setState(() => _counter++), | |
child: Container( | |
color: Colors.red, | |
child: Center(child: Text('tap for increment - counter : $_counter'))))), | |
Positioned( | |
bottom: 0, | |
height: MediaQuery.of(context).size.height, | |
width: MediaQuery.of(context).size.width, | |
child: SingleChildScrollView( | |
child: Container( | |
margin: EdgeInsets.only( | |
top: MediaQuery.of(context).size.height - 145), | |
width: MediaQuery.of(context).size.width, | |
color: Colors.grey, | |
child: Column( | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
MaterialButton( | |
onPressed: () => previousStep(), | |
child: Text('Previous'), | |
), | |
MaterialButton( | |
onPressed: () => nextStep(), | |
child: Text('Next'), | |
) | |
], | |
), | |
AnimatedSwitcher( | |
duration: Duration(milliseconds: 200), | |
child: _switchers[_currentWidget], | |
) | |
], | |
), | |
), | |
)) | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment