Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created August 20, 2021 11:33
Show Gist options
  • Save doyle-flutter/78056a2faaf542e992e89402e9897614 to your computer and use it in GitHub Desktop.
Save doyle-flutter/78056a2faaf542e992e89402e9897614 to your computer and use it in GitHub Desktop.
Rolling&Move
import 'package:flutter/material.dart';
void main() => runApp(Sys());
class Sys extends StatelessWidget {
const Sys({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(home: Main());
}
}
class Main extends StatefulWidget {
const Main({Key? key}) : super(key: key);
@override
_MainState createState() => _MainState();
}
class _MainState extends State<Main> with SingleTickerProviderStateMixin {
Animation<double>? _anim;
AnimationController? _ac;
@override
void initState() {
this._ac = AnimationController(vsync: this, duration: Duration(seconds: 2))
..addListener(() {
if(!this.mounted) return;
setState(() {});
if(this._ac!.isCompleted){
Future(() async{
bool back = await Navigator.of(context).push<bool>(
MaterialPageRoute(builder: (BuildContext context) => PageTwo())
) ?? true;
if(back){
this._ac!.reset();
await this._ac!.forward();
}
});
return;
}
});
this._anim = Tween<double>(begin: 0, end: 3).animate(this._ac!);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: this._ac == null || this._anim == null
? Container(child: Text("Load"),)
: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Transform.translate(
offset: Offset((this._anim?.value??0)*(MediaQuery.of(context).size.width-250), 0),
child: Transform.rotate(
angle: this._anim?.value ?? 0,
child: InkWell(
borderRadius: BorderRadius.circular(200.0),
onTap: (){
if(this._ac == null || _anim == null) return;
if(this._ac!.isAnimating) return;
this._ac!.forward();
return;
},
child: Container(
width: 200.0,
height: 200.0,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 8.0),
borderRadius: BorderRadius.circular(200.0),
),
alignment: Alignment.center,
child: Text("JamesDev", style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold, color: Colors.red),),
),
),
),
)
],
),
),
);
}
}
class PageTwo extends StatelessWidget {
const PageTwo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: Text("PageTwo"),
centerTitle: true,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment