Skip to content

Instantly share code, notes, and snippets.

@JohanScheepers
Last active November 6, 2024 19:42
Show Gist options
  • Save JohanScheepers/cc7d7401340ee21ecb619c5415cdcdd4 to your computer and use it in GitHub Desktop.
Save JohanScheepers/cc7d7401340ee21ecb619c5415cdcdd4 to your computer and use it in GitHub Desktop.
SecretPage page tap
//Please solve this one.
//
//If I tap on any one of the eight areas app navigate to “PageTwo()”
//
//If I tap on four of the areas simultaneous (I use four fingers to tap with), I want to navigate the “SecretPage()“.
//
//Lets pick “One”, “Two”, “Five” and “Six” as the as the secrete tap areas.
import 'package:flutter/material.dart';
const pageTwo = '/pageTwo';
const secretPage = "/secretPage";
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Touch Four',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Touch Four'),
routes: {
pageTwo: (context) => const PageTwo(),
secretPage: (context) => const SecretPage()
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const Center(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [TouchArea(name: "One"), TouchArea(name: "Two")],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [TouchArea(name: "Three"), TouchArea(name: "Four")],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [TouchArea(name: "Five"), TouchArea(name: "Six")],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [TouchArea(name: "Seven"), TouchArea(name: "Eight")],
),
],
),
),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class TouchArea extends StatefulWidget {
const TouchArea({required this.name, super.key});
final String name;
@override
State<TouchArea> createState() => _TouchAreaState();
}
class _TouchAreaState extends State<TouchArea> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const PageTwo()));
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 100,
height: 40,
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(child: Text(widget.name)),
)),
));
}
}
class PageTwo extends StatelessWidget {
const PageTwo({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Page Two"),
),
body: const Center(
child: Text("Page Two"),
),
);
}
}
class SecretPage extends StatelessWidget {
const SecretPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Secret Page"),
),
body: const Center(
child: Text("Secret Page"),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment