hsx 0.0.2 copy "hsx: ^0.0.2" to clipboard
hsx: ^0.0.2 copied to clipboard

hsx personal demo

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hsx/hsx.dart';
import 'package:hsx_example/delegate/navigator.dart';
import 'package:hsx_example/delegate/route_information_parser.dart';
import 'package:hsx_example/delegate/router_delegate.dart';
import 'package:hsx_example/navigator_v2/router_delegate.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _hsxPlugin = Hsx();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _hsxPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  int changeIndex = 0;
  final VeggieRouterDelegate _routerDelegate = VeggieRouterDelegate();
  final XDragonRouterParser _routeInformationParser = XDragonRouterParser(initRouter: '/home');
  final RouteDelegate _delegate = RouteDelegate(
      onGenerateRoute: XLNavigator.onGenerateXLRoute,
      navigatorKeyParam: XLNavigator.rootNavigatorKey,
      initialRoute: '/home',
      navigatorObserver: [
        // BotToastNavigatorObserver(),
        // XDragonApp.createRouteObserver(XLNavigator.rootNavigatorKey),
        // // XDragonNavigatorObserver(),
        // // TracerObserver(),
        // LoggerObserver(),
        // SentryObserver(),
      ]);

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      //  routerDelegate: _delegate,
      title: 'Flutter Fly',
      theme: ThemeData(primaryColor: Colors.white, accentColor: Color(0xFF8eC782), backgroundColor: Color(0xFFF9F2F2)),
      debugShowCheckedModeBanner: false,
      //  routerDelegate: _routerDelegate,
      routerDelegate: _delegate,
      routeInformationParser: _routeInformationParser,
      // routeInformationParser: XDragonRouterParser(initRouter: '/Users/xpeng/xp/share_plugin/example/lib/page/home'),
    );

    // return MaterialApp(
    //   home: Scaffold(
    //     appBar: AppBar(
    //       title: const Text('Plugin example app'),
    //     ),
    //     body: Center(
    //       child: SingleChildScrollView(
    //         child: Column(
    //           children: [
    //             Text('Running on: $_platformVersion\n'),
    //             const SizedBox(
    //               height: 20,
    //             ),
    //             Builder(builder: (context) {
    //               return GestureDetector(
    //                 onTap: () async {
    //                   final RenderBox box = context.findRenderObject() as RenderBox;
    //                   await _hsxPlugin.getShare(sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
    //                 },
    //                 child: Container(
    //                   padding: const EdgeInsets.all(20),
    //                   color: Colors.green,
    //                   child: const Text(
    //                     'εˆ†δΊ«',
    //                     style: TextStyle(
    //                         height: 22 / 14, fontSize: 20, color: Color(0xff31456A), fontWeight: FontWeight.w500),
    //                   ),
    //                 ),
    //               );
    //             }),
    //           ],
    //         ),
    //       ),
    //     ),
    //   ),
    // );
  }
}