我是个新手。我从GitHub获得了动画Flutter登录页面的代码,并且正在对其进行修改以满足自己的要求。我从另一个在其工作的应用程序中复制了webview的代码,但是当我单击新应用程序中的按钮时,什么也没有发生。
这是修改后的代码:
答案 0 :(得分:0)
您可以在下面复制粘贴运行完整代码
您可以将MaterialApp
移至main()
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays([]);
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyApp()));
}
工作演示
完整代码
import 'package:avatar_glow/avatar_glow.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'package:webview_flutter/webview_flutter.dart';
class DelayedAnimation extends StatefulWidget {
final Widget child;
final int delay;
DelayedAnimation({@required this.child, this.delay});
@override
_DelayedAnimationState createState() => _DelayedAnimationState();
}
class _DelayedAnimationState extends State<DelayedAnimation>
with TickerProviderStateMixin {
AnimationController _controller;
Animation<Offset> _animOffset;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(milliseconds: 800));
final curve =
CurvedAnimation(curve: Curves.decelerate, parent: _controller);
_animOffset =
Tween<Offset>(begin: const Offset(0.0, 0.35), end: Offset.zero)
.animate(curve);
if (widget.delay == null) {
_controller.forward();
} else {
Timer(Duration(milliseconds: widget.delay), () {
_controller.forward();
});
}
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return FadeTransition(
child: SlideTransition(
position: _animOffset,
child: widget.child,
),
opacity: _controller,
);
}
}
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays([]);
runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyApp()));
}
class MyWebView extends StatelessWidget {
final String title;
final String selectedUrl;
final Completer<WebViewController> _controller =
Completer<WebViewController>();
MyWebView({
@required this.title,
@required this.selectedUrl,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: WebView(
initialUrl: selectedUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
));
}
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
final int delayedAmount = 500;
double _scale;
AnimationController _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: Duration(
milliseconds: 200,
),
lowerBound: 0.0,
upperBound: 0.1,
)..addListener(() {
setState(() {});
});
super.initState();
}
@override
Widget build(BuildContext context) {
final color = Colors.white;
_scale = 1 - _controller.value;
return Scaffold(
backgroundColor: Color(0xFF1E88E5),
body: Center(
child: Column(
children: <Widget>[
AvatarGlow(
endRadius: 90,
duration: Duration(seconds: 2),
glowColor: Colors.white24,
repeat: true,
repeatPauseDuration: Duration(seconds: 2),
startDelay: Duration(seconds: 1),
child: Material(
elevation: 8.0,
shape: CircleBorder(),
child: CircleAvatar(
backgroundColor: Colors.grey[100],
child: FlutterLogo(
size: 50.0,
),
radius: 50.0,
)),
),
DelayedAnimation(
child: Text(
"Hi There",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25.0,
color: color),
),
delay: delayedAmount + 1000,
),
DelayedAnimation(
child: Text(
"Welcome to DocSpot",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: color),
),
delay: delayedAmount + 2000,
),
SizedBox(
height: 30.0,
),
DelayedAnimation(
child: Text(
"Your New Personal",
style: TextStyle(fontSize: 15.0, color: color),
),
delay: delayedAmount + 3000,
),
DelayedAnimation(
child: Text(
"Healthcare Companion",
style: TextStyle(fontSize: 15.0, color: color),
),
delay: delayedAmount + 3000,
),
SizedBox(
height: 100.0,
),
DelayedAnimation(
child: GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
child: Transform.scale(
scale: _scale,
child: _animatedButtonUI,
),
),
delay: delayedAmount + 4000,
),
SizedBox(
height: 50.0,
),
DelayedAnimation(
child: new MaterialButton(
height: 60.0,
minWidth: 270.0,
color: Colors.white,
textColor: Color(0xFF1E88E5),
child: new Text("Register"),
onPressed: () => {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => MyWebView(
title: "DocHelp",
selectedUrl: "https://flutter.dev/",
))),
},
splashColor: Colors.blueAccent[300],
),
delay: delayedAmount + 5000,
),
],
),
)
// Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// Text('Tap on the Below Button',style: TextStyle(color: Colors.grey[400],fontSize: 20.0),),
// SizedBox(
// height: 20.0,
// ),
// Center(
// ),
// ],
// ),
);
}
Widget get _animatedButtonUI => Container(
height: 60,
width: 270,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100.0),
color: Colors.white,
),
child: Center(
child: Text(
'Login',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Color(0xFF1E88E5),
),
),
),
);
void _onTapDown(TapDownDetails details) {
_controller.forward();
}
void _onTapUp(TapUpDetails details) {
_controller.reverse();
}
}