about_page.dart 3.12 KB
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:Parlando/res/resources.dart';
import 'package:Parlando/routers/fluro_navigator.dart';
import 'package:Parlando/util/device_utils.dart';
import 'package:Parlando/util/other_utils.dart';
import 'package:Parlando/util/toast_utils.dart';
import 'package:Parlando/widgets/click_item.dart';
import 'package:Parlando/widgets/my_app_bar.dart';

import 'package:Parlando/extension/int_extension.dart';

class AboutPage extends StatefulWidget {
  const AboutPage({Key? key}) : super(key: key);

  @override
  _AboutPageState createState() => _AboutPageState();
}

class _AboutPageState extends State<AboutPage> {
  final List<FlutterLogoStyle> _styles = <FlutterLogoStyle>[
    FlutterLogoStyle.stacked,
    FlutterLogoStyle.markOnly,
    FlutterLogoStyle.horizontal
  ];

  final List<Cubic> _curves = <Cubic>[
    Curves.ease,
    Curves.easeIn,
    Curves.easeInOutCubic,
    Curves.easeInOut,
    Curves.easeInQuad,
    Curves.easeInCirc,
    Curves.easeInBack,
    Curves.easeInOutExpo,
    Curves.easeInToLinear,
    Curves.easeOutExpo,
    Curves.easeInOutSine,
    Curves.easeOutSine,
  ];

  // 取随机颜色
  Color _randomColor() {
    final int red = Random.secure().nextInt(255);
    final int greed = Random.secure().nextInt(255);
    final int blue = Random.secure().nextInt(255);
    return Color.fromARGB(255, red, greed, blue);
  }

  Timer? _countdownTimer;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      // 2s定时器
      _countdownTimer = Timer.periodic(const Duration(seconds: 2), (_) {
        // https://www.jianshu.com/p/e4106b829bff
        if (!mounted) {
          return;
        }
        setState(() {});
      });
    });
  }

  @override
  void dispose() {
    _countdownTimer?.cancel();
    _countdownTimer = null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        homeMenuHeader: Container(
          alignment: Alignment.center,
          width: double.infinity,
          child: const Text(
            "关于我们",
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
      ),
      body: Column(
        children: <Widget>[
          Gaps.vGap50,
          FlutterLogo(
            size: 100.px,
            textColor: _randomColor(),
            style: _styles[Random.secure().nextInt(3)],
            curve: _curves[Random.secure().nextInt(12)],
          ),
          Gaps.vGap10,
          ClickItem(
            title: '项目官网',
            onTap: () => _launchWebURL('项目官网', 'http://www.mofunsky.com/'),
          ),
          Gaps.vGap10,
          ClickItem(
            title: '自我介绍',
            onTap: () {
              Toast.show('我们是一首很有诗意的APP~');
            },
          ),
        ],
      ),
    );
  }

  void _launchWebURL(String title, String url) {
    if (Device.isMobile) {
      NavigatorUtils.goWebViewPage(context, title, url);
    } else {
      Utils.launchWebURL(url);
    }
  }
}