Skip to content

Instantly share code, notes, and snippets.

@Rahiche
Created January 2, 2020 04:18
Show Gist options
  • Save Rahiche/f24b75ecebc67dd07c5ecc306e000b52 to your computer and use it in GitHub Desktop.
Save Rahiche/f24b75ecebc67dd07c5ecc306e000b52 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool showFirst = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(
overflow: Overflow.visible,
children: <Widget>[
AnimatedPositioned(
duration: Duration(seconds: 1),
bottom: 10,
height: 200,
right: showFirst ? 0 : MediaQuery.of(context).size.width,
left: showFirst ? 0 : -MediaQuery.of(context).size.width,
child: Container(
width: MediaQuery.of(context).size.width - 100,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.red,
child: Center(
child: FlatButton(
onPressed: () {
setState(() {
showFirst = !showFirst;
});
},
child: Text("Next"),
),
),
),
),
),
),
AnimatedPositioned(
duration: Duration(seconds: 1),
bottom: 10,
height: 200,
right: showFirst ? -MediaQuery.of(context).size.width : 0,
left: showFirst ? MediaQuery.of(context).size.width : 0,
child: Container(
width: MediaQuery.of(context).size.width - 100,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.blue,
child: Center(
child: FlatButton(
onPressed: () {
setState(() {
showFirst = !showFirst;
});
},
child: Text("Previous"),
),
),
),
),
),
)
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment