效果图
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() {
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);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85