效果图
dart
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'jumpPage.dart';
class TransitPage extends StatefulWidget {
const TransitPage({super.key});
@override
State<TransitPage> createState() => _TransitPage();
}
class _TransitPage extends State<TransitPage> {
late Timer _timer;
int _currentTime = 6;
@override
void initState() {
// TODO: implement initState
super.initState();
_timer = Timer.periodic(Duration(milliseconds: 1000), (timer) {
setState(() {
_currentTime--;
});
if(_currentTime<=0){
_jumpRoutePage();
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Image.asset(
"images/page.png",
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
),
Positioned(
top: MediaQuery.of(context).padding.top+30,
right: MediaQuery.of(context).padding.right+30,
child: InkWell(
child: _clipButton(),
onTap: (){
_jumpRoutePage();
},
),
)
],
),
);
}
Widget _clipButton() {
return ClipRRect(
borderRadius: BorderRadius.circular(40),
child: Container(
height: 50,
width: 50,
color: Colors.black.withOpacity(0.5),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("跳过",style: TextStyle(color: Colors.white,fontSize: 12),),
Text("${_currentTime}s",style: TextStyle(color: Colors.white,fontSize: 12),),
],
),
),
);
}
//倒计结束或点击跳过后的页面
void _jumpRoutePage() {
_timer.cancel();
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (BuildContext context)=>TransitPage2()), (route) => false);
}
}