import 'dart:async';
import 'dart:developer';

import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:hub/shared/mixins/switcher_mixin.dart';
import 'package:hub/shared/utils/storage_util.dart';

import '/components/templates_components/welcome_template_component/welcome_template_component_widget.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import 'welcome_page_model.dart';

export 'welcome_page_model.dart';

class WelcomePageWidget extends StatefulWidget with Switcher {
  const WelcomePageWidget({super.key});

  @override
  State<WelcomePageWidget> createState() => _WelcomePageWidgetState();
}

class _WelcomePageWidgetState extends State<WelcomePageWidget> {
  late WelcomePageModel _model;

  final scaffoldKey = GlobalKey<ScaffoldState>();

  @override void initState() {
    super.initState();
    _model = createModel(context, () => WelcomePageModel());

    // On page load action.
    SchedulerBinding.instance.addPostFrameCallback((_) async {
      if (isAndroid == true) {
        StorageUtil().deviceType = 'Android';
        setState(() {});
      } else if (isiOS == true) {
        StorageUtil().deviceType = 'iOS';
        setState(() {});
      } else {
        StorageUtil().deviceType = 'Web';
        setState(() {});
      }
    });
  }

  @override void dispose() {
    _model.dispose();

    super.dispose();
  }



  @override
  Widget build(BuildContext context) {
    StorageUtil().context = context;
    return GestureDetector(
      onTap: () => _model.unfocusNode.canRequestFocus
          ? FocusScope.of(context).requestFocus(_model.unfocusNode)
          : FocusScope.of(context).unfocus(),
      child: Scaffold(
        key: scaffoldKey,
        backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
        body: SafeArea(
          top: true,
          child: wrapWithModel(
            model: _model.welcomeTemplateComponentModel,
            updateCallback: () => setState(() {}),
            updateOnChange: true,
            child: WelcomeTemplateComponentWidget(
              toggleSignUpPage: () async {
                await Switcher.toggleSignUpPage(context);
              },
              toggleSignInPage: () async {
                await Switcher.toggleSignInPage(context);
              },
            ),
          ),
        ),
      ),
    );
  }
}
