Skip to content

Instantly share code, notes, and snippets.

@Ticore
Last active March 17, 2020 19:08
Show Gist options
  • Save Ticore/a3d54ade5fee4020e3e7fb2993935ca8 to your computer and use it in GitHub Desktop.
Save Ticore/a3d54ade5fee4020e3e7fb2993935ca8 to your computer and use it in GitHub Desktop.
flutter multi app
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import './app01.dart' as App01;
import './app02.dart' as App02;
void interceptOnPointerDataPacket(Function callback) {
var _onPointerDataPacket = ui.window.onPointerDataPacket;
int _upEventCount = 0;
ui.window.onPointerDataPacket = (ui.PointerDataPacket packet) {
Timer delayCleatUpTimer;
_onPointerDataPacket(packet);
_upEventCount += packet.data
.where((datum) => datum.change == ui.PointerChange.up)
.length;
if (_upEventCount >= 3) {
_upEventCount = 0;
runApp(AppListWidget());
callback();
} else {
delayCleatUpTimer?.cancel();
delayCleatUpTimer =
Timer(Duration(milliseconds: 100), () => _upEventCount = 0);
}
};
}
void main() {
runApp(AppListWidget());
interceptOnPointerDataPacket(() => runApp(AppListWidget()));
}
Map<String, Function> appMap = {
'App01': () => App01.MyApp(),
'App02': () => App02.MyApp(),
};
class AppListWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter App List",
theme: ThemeData(primaryColor: Colors.deepPurple),
home: Scaffold(
body: ListView(
children: appMap.entries.map((entry) {
return ListTile(
title: Text(entry.key),
onTap: () => runApp(entry.value()),
);
}).toList(),
),
),
showPerformanceOverlay: false,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment