Saturday, June 5, 2021

【FLUTTER ANDROID STUDIO and IOS】animated modal barrier

 import 'package:flutter/material.dart';


void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: AnimatedDemoScreen(),
);
}
}

class AnimatedDemoScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _AnimatedDemoScreenState();
}

class _AnimatedDemoScreenState extends State<AnimatedDemoScreen>
with SingleTickerProviderStateMixin {
bool _isLoading = false;
Widget _animatedModalBarrier;

AnimationController _animationController;
Animation<Color> _colorAnimation;

@override
void initState() {
ColorTween _colorTween = ColorTween(
begin: Color.fromARGB(200, 155, 120, 155),
end: Color.fromARGB(100, 127, 127, 127),
);

_animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 3)
);
_colorAnimation = _colorTween.animate(_animationController);

_animatedModalBarrier = AnimatedModalBarrier(
color: _colorAnimation,
dismissible: true,
);

super.initState();
}

List<Widget> buildList(BuildContext context) {
List<Widget> widgets = <Widget>[
RaisedButton(
padding: EdgeInsets.only(left: 40, right: 40),
color: Colors.teal[200],
child: Text('Press'),
onPressed: () {
setState(() {
_isLoading = true;
});

_animationController.reset();
_animationController.forward();

Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Button is press'),
backgroundColor: Colors.black,),
);

Future.delayed(const Duration(seconds: 5), () {
setState(() {
_isLoading = false;
});
});
},
),
];

if (_isLoading) {
widgets.add(_animatedModalBarrier);
}

return widgets;
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey[100],
appBar: AppBar(
backgroundColor: Colors.black,
automaticallyImplyLeading: false,
title: Text('Flutter AnimatedModalBarrier Demo'),
),
body: Builder(
builder: (context) =>
Center(
child: Padding(
padding: EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 100.0,
width: 250.0,
child: Stack(
alignment: AlignmentDirectional.center,
children: buildList(context),
),
),
],
),
),
),
),
);
}
}

No comments:

Post a Comment

End of Summer Sale ☀️😎

20% OFF Inside!🤯 ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏...