提问者:小点点

如何只制作一次入职屏幕



我想在设备中安装应用程序时只显示一次我的入职屏幕

导入'包:flutter/基础. dart';导入'包:flutter/材料.dart';导入'包:flutter/services.dart';导入'包:introduction_screen/introduction_screen.dart';

导入widget_tree. dart;

扩展StatefulWidget{@overwrite_IntroScreenStatecreateState()=

类_IntroScreenState扩展State{最终intinKey=GlobalKey();后期最终bool isFirstRun; get child=

void onInfEnd(context){Navigator. of(context).push(MaterialPageRoute(builder:()=

Widget_buildFullscreenImage(){返回Image.资产('资产/图像/intro1. png',适合:BoxFit.cover,高度:双精度,宽度:双精度,对齐方式:Alignment.center);}

Widget_buildImage(String assetName,[double wide=350]){返回Image.资产('资产/$assetName',宽度:宽度);}

@overwrite Widget build(BuildContext context){const body Style=TextStyle(fontSize: 19.0);

const pageDecoration = PageDecoration(
  titleTextStyle: TextStyle(
      color: Color.fromARGB(255, 29, 116, 182),
      fontSize: 30.0,
      fontWeight: FontWeight.w700,
      fontFamily: 'assets/fonts/Ubuntu-B.ttf'),
  bodyTextStyle: bodyStyle,
  bodyPadding: EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 16.0),
  pageColor: Color.fromARGB(0, 255, 255, 255),
  imagePadding: EdgeInsets.zero,
);

return IntroductionScreen(
  key: introKey,
  globalBackgroundColor: Colors.white,
  globalHeader: const Align(
    alignment: Alignment.topRight,
    child: SafeArea(
      child: Padding(
        padding: EdgeInsets.only(top: 16, right: 16),
        // child: _buildImage('flutter.png', 100),
      ),
    ),
  ),
  /*globalFooter: SizedBox(
    width: double.infinity,
    height: 60,
    child: ElevatedButton(
      style:const ButtonStyle(alignment:Alignment(1, 1)),
      child: const Text(
        'Skip!',
        style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
      ),
      onPressed: () => _onIntroEnd(context),
    ),
  ),*/

  pages: [
    PageViewModel(
      title: ('WELCOME'),
      body:
          'To the Mawed , which allows you to book a clinic easily . Choose the hospital that suits you and the doctor you want.',
      image: Image.asset(
        'assets/images/intro1.png',
        width: 400,
        height: 400,
        fit: BoxFit.fitWidth,
        alignment: AlignmentDirectional.bottomCenter,
      ),
      decoration: pageDecoration,
    ),
    PageViewModel(
      title: "Book Now",
      body: " From your home easly & Keep the ticket to show when asked",
      image: Image.asset(
        'assets/images/intro2.jpg',
        width: 350,
        height: 350,
        fit: BoxFit.fitWidth,
        alignment: AlignmentDirectional.center,
      ),
      decoration: pageDecoration,
    ),
    PageViewModel(
      title: "Avoid",
      body: "Crowding and wasting time, and go on time.",
      image: Image.asset(
        'assets/images/intro3.jpg',
        width: 350,
        height: 350,
        fit: BoxFit.fitWidth,
        alignment: AlignmentDirectional.center,
      ),
      decoration: pageDecoration,
    ),
    PageViewModel(
      title: "Choose the hospital",
      body: "That suits & the closest to you",
      image: Image.asset(
        'assets/images/intro4.jpg',
        width: 350,
        height: 350,
        fit: BoxFit.fitWidth,
        alignment: AlignmentDirectional.center,
      ),
      decoration: pageDecoration,
    ),
    PageViewModel(
      title: "What do you feel ?",
      body: "Choose the clinic or medical specialty carefully",
      image: Image.asset('assets/images/intro5.png',
          width: 350,
          height: 350,
          fit: BoxFit.fitWidth,
          alignment: AlignmentDirectional.center),
      decoration: pageDecoration,
    ),
    PageViewModel(
      title: "Get to know ",
      body: "Your doctor's appointments and choose the time you want.",
      image: Image.asset('assets/images/intro6.png',
          width: 400,
          height: 400,
          fit: BoxFit.fitWidth,
          alignment: AlignmentDirectional.bottomCenter),
      decoration: pageDecoration,
    ),
  ],
  onDone: () => _onIntroEnd(context),
  onSkip: () => _onIntroEnd(context), // You can override onSkip callback
  showSkipButton: false,
  skipOrBackFlex: 0,
  nextFlex: 0,
  showBackButton: true,
  //rtl: true, // Display as right-to-left
  back: const Icon(Icons.arrow_back),
  skip: const Text('Skip', style: TextStyle(fontWeight: FontWeight.w600)),
  next: const Icon(Icons.arrow_forward),
  done:
      const Text('Book Now', style: TextStyle(fontWeight: FontWeight.w600)),
  curve: Curves.fastLinearToSlowEaseIn,
  controlsMargin: const EdgeInsets.all(16),
  controlsPadding: kIsWeb
      ? const EdgeInsets.all(12.0)
      : const EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
  dotsDecorator: const DotsDecorator(
    size: Size(10.0, 10.0),
    color: Color(0xFFBDBDBD),
    activeSize: Size(22.0, 10.0),
    activeShape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(25.0)),
    ),
  ),
  dotsContainerDecorator: const ShapeDecoration(
    color: Colors.black87,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(8.0)),
    ),
  ),
);

} }


共3个答案

匿名用户

处理此问题的常见方法是使用SharedPre的库

1-在显示入职时,在SharedPre的值true
中存储一个bool,就像hasSeenOn的2-在显示入职之前,从首选项中获取boolhasSeenOn的
如果是false,您可以显示入职,否则您应该跳过它

匿名用户

你可以使用这个库

您只需配置一次即可将数据保存在本地

匿名用户

由于其他答案建议使用SharedPre和LocalSave,因此当您没有任何用户帐户时,它可以正常工作。

如果您有用户帐户和数据库,您应该将此状态保存在他们的配置文件中,这样即使他们在新设备上安装了应用程序,他们也不会再次入职,如果您设置一些用户只能访问一次的特定数据,可能会导致问题。

您基本上在创建用户时将bool hasCompletedOn的设置为false,并在他完成入职后更新它。

然后按照FDuhen的指定,您是否显示入职。