/*
*@Author: XianKaiQun
*@Date: 2020-04-20 00:57:53
 * @LastEditors: wuwei 
 * @LastEditTime: 2025-03-13 15:43:28
*@Descripttion: 
*/
import 'package:app_package/src/assets.gen.dart';
import 'package:app_package/src/route_observer_util.dart';
import 'package:app_package/src/routes.dart';
import 'package:app_package/src/styles/theme_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class AppView extends StatelessWidget {
  const AppView({Key? key}) : super(key: key);

  void hideKeyboard(BuildContext context) {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus!.unfocus();
    }
  }

  // double adaptUnit() {
  //   final physicalSize = ui.window.physicalSize;
  //   final width = (physicalSize.width < physicalSize.height)
  //       ? physicalSize.width
  //       : physicalSize.height;

  //   final devicePixelRatio = ui.window.devicePixelRatio;

  //   if (width == 0 || devicePixelRatio == 0) return 1.0;
  //   if ((width / devicePixelRatio / 375.0) < 1) return 1.2;
  //   return (width / devicePixelRatio / 375.0) >= 1.1
  //       ? 1.1
  //       : (width / devicePixelRatio / 375.0);
  // }

  @override
  Widget build(BuildContext context) {
    Widget current = GetMaterialApp(
      navigatorKey: WNavUtil.instance!.navigatorKey,
      initialRoute: 'splash',
      onGenerateRoute: onGenerateRoute,
      navigatorObservers: [RouteObserverUtil().routeObserver], //添加路由观察者
      theme: appThemeData,
      title: '绘服务',

      ///国际化 flutter中，默认tip都是英文的  需要改成中文
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh', 'CH'),
        const Locale('en', 'US'),
      ],
      locale: const Locale('zh', 'CH'),
      builder: (context, child) => Scaffold(
        // Global GestureDetector that will dismiss the keyboard
        // 全局点击空白收起键盘，减少许多代码
        body: GestureDetector(
          onTap: () {
            hideKeyboard(context);
          },
          child: child,
        ),
      ),
    );
    current = WTheme(data: WThemeData.fallback(), child: current);
    return current;
  }
}

class Page404 extends StatelessWidget {
  const Page404({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('抱歉！',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Image(
                image: AssetList.$error_404_png_image, width: 168, height: 90),
            Container(
              height: 20,
            ),
            Text(
              '很抱歉，该页面貌似迷路走丢了！',
              style: TextStyle(color: Colors.grey[700]),
            ),
          ],
        ),
      ),
    );
  }
}
