| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- import 'dart:async';
- import 'package:fast/constants.dart';
- import 'package:fast/utils/api.dart';
- import 'package:fast/utils/global.dart';
- import 'package:fast/utils/http_utils.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
- import 'package:get/get.dart';
- import 'package:intl/intl.dart';
- class ChangeTime extends StatefulWidget {
- List<dynamic> list;
- var callback;
- ChangeTime({Key? key, required this.list,required this.callback}) : super(key: key);
- @override
- State<ChangeTime> createState() => _ChangeTimeState();
- }
- class _ChangeTimeState extends State<ChangeTime>
- with SingleTickerProviderStateMixin {
- late AnimationController controller;
- late Animation animation;
- late Timer timerUpdate;
- String strSysTime = '';
- @override
- void initState() {
- controller = AnimationController(
- vsync: this, duration: const Duration(milliseconds: 300));
- controller.addListener(() {
- setState(() {});
- });
- animation = Tween(begin: 0.0, end: 1.0).animate(
- CurvedAnimation(parent: controller, curve: const Interval(0.0, 1.0)));
- controller.forward();
- showSystemTime();
- super.initState();
- }
- @override
- void dispose() {
- controller.dispose();
- timerUpdate.cancel();
- super.dispose();
- }
- close() {
- controller.reverse();
- Timer(const Duration(milliseconds: 300), () {
- Navigator.of(context).pop();
- });
- }
- void showSystemTime() {
- timerUpdate = Timer.periodic(const Duration(seconds: 1), (e) {
- int milliseconds = DateTime.now().millisecondsSinceEpoch;
- milliseconds = milliseconds + Global().timeSeconds * 1000;
- DateTime dt = DateTime.fromMillisecondsSinceEpoch(milliseconds);
- if (mounted) {
- setState(() {
- strSysTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(dt);
- });
- }
- });
- }
- DateTime serverTime() {
- int milliseconds = DateTime.now().millisecondsSinceEpoch;
- milliseconds = milliseconds + Global().timeSeconds * 1000;
- return DateTime.fromMillisecondsSinceEpoch(milliseconds);
- }
- Future updateTimes(seconds) async {
- Map<String, dynamic> data =
- await HttpUtils.get(Api.fixTime, params: {"fix": seconds});
- widget.callback();
- }
- showPicker(int seconds) {
- DateTime dt = DateTime.fromMillisecondsSinceEpoch(seconds*1000);
- DatePicker.showDatePicker(context,
- showTitleActions: true,
- currentTime: dt,
- theme: const DatePickerTheme(
- headerColor: Colors.orange,
- backgroundColor: Colors.white,
- itemStyle: TextStyle(
- color: Colors.black, fontWeight: FontWeight.bold, fontSize: 18),
- doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
- onConfirm: (date) {
- DatePicker.showTimePicker(context,
- showTitleActions: true,
- currentTime: dt,
- theme: const DatePickerTheme(
- headerColor: Colors.orange,
- backgroundColor: Colors.white,
- itemStyle: TextStyle(
- color: Colors.black,
- fontWeight: FontWeight.bold,
- fontSize: 18),
- doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
- onConfirm: (date2) {
- DateTime dt = DateTime.parse(date.year.toString() +
- '-' +
- (date.month.toString()).padLeft(2, '0') +
- '-' +
- (date.day.toString()).padLeft(2, '0') +
- 'T' +
- (date2.hour.toString()).padLeft(2, '0') +
- ':' +
- (date2.minute.toString()).padLeft(2, '0') +
- ':' +
- (date2.second.toString()).padLeft(2, '0'));
- int seconds = (dt.millisecondsSinceEpoch -
- DateTime.now().millisecondsSinceEpoch) ~/
- 1000;
- updateTimes(seconds);
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- double screenHeight = MediaQuery.of(context).size.height;
- return Stack(
- children: [
- GestureDetector(
- onTap: () {
- close();
- },
- child: Container(
- width: 375.px,
- height: screenHeight * 0.2,
- color: Colors.transparent,
- ),
- ),
- Positioned(
- bottom: -(1 - animation.value) * screenHeight * 0.8,
- child: Container(
- width: 375.px,
- padding: EdgeInsets.all(20.px),
- height: screenHeight * 0.8,
- decoration: BoxDecoration(
- color: const Color(0x99000000),
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(16.px),
- topRight: Radius.circular(16.px))),
- child: Column(
- children: [
- Row(
- children: [
- SizedBox(
- width: 160.px,
- child: Text(
- '系统时间',
- style:
- TextStyle(color: Colors.white, fontSize: 12.px),
- ),
- ),
- SizedBox(
- width: 148.px,
- child: Text(
- strSysTime,
- style:
- TextStyle(color: Colors.white, fontSize: 12.px),
- ),
- ),
- GestureDetector(
- onTap: () {
- updateTimes(0);
- },
- child: Text('重置',
- style: TextStyle(
- color: Colors.white, fontSize: 12.px)),
- )
- ],
- ),
- SizedBox(
- height: 20.px,
- ),
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- ...List<Widget>.generate(widget.list.length, (i) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: 334.px,
- padding: EdgeInsets.only(bottom: 10.px),
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(
- color: const Color(0x4DFFFFFF),
- width: 1.px))),
- child: Text(
- widget.list[i]['day'],
- style: TextStyle(
- color: kThemeColor, fontSize: 14.px),
- ),
- ),
- Column(
- children: [
- ...List<Widget>.generate(
- widget.list[i]['contents'].length,
- (index) {
- String strColor = widget.list[i]['contents']
- [index]['fColor'];
- strColor = strColor.substring(2, 10);
- int value = int.parse(strColor, radix: 16);
- return Container(
- width: 334.px,
- height: 40.px,
- alignment: Alignment.centerLeft,
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(
- color:
- const Color(0x4DFFFFFF),
- width: 1.px))),
- child: Row(
- mainAxisSize: MainAxisSize.max,
- children: [
- SizedBox(
- width: 160.px,
- child: Text(
- widget.list[i]['contents'][index]
- ['name'],
- style: TextStyle(
- color: Color(value),
- fontSize: 12.px),
- ),
- ),
- GestureDetector(
- onTap: () {
- int seconds = int.parse(widget
- .list[i]['contents']
- [index]['time']) -
- (DateTime.now()
- .millisecondsSinceEpoch) ~/
- 1000;
- updateTimes(seconds);
- // showPicker();
- },
- child: SizedBox(
- width: 148.px,
- child: Text(
- widget.list[i]['contents']
- [index]['timeStr'],
- style: TextStyle(
- color: Color(value),
- fontSize: 12.px),
- ),
- )),
- GestureDetector(
- onTap: () {
- showPicker(int.parse(widget
- .list[i]['contents']
- [index]['time']));
- },
- child: Text(
- '选择',
- style: TextStyle(
- color: kThemeColor,
- fontSize: 12.px),
- ))
- ],
- ),
- );
- })
- ],
- )
- ],
- );
- })
- ],
- ),
- ))
- ],
- ),
- )),
- Positioned(
- left: 0.0,
- top: 0.2*screenHeight,
- child: GestureDetector(child: Container(width: 300.px,height: 60.px,color: Colors.transparent,),onVerticalDragStart: (details) => {
- close()
- },))
- ],
- );
- }
- }
|