import 'package:flutter/material.dart'; //Screw it, I'm going to use the old one anyways. For some reason, my attempts //at simplifying this code didn't work... void main() { runApp(const MyApp()); } //On this lesson, we'll learn how to create second pages for an app //without using the settings buttons on the bottom and use our own //buttons instead. class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: "Flutter Demo 2", home: FirstPage(), ); } } //We will always have one MaterialApp() in our main function, and //that will be like the main function. Using this main function, we'll //set one home page, and then use external Stateless or StatefulWidget classes //as our pages, and the return will be the Scaffolds of these pages. //We always ned out main MyApp or "MaterialApp" widget to be UI-wise empty. class FirstPage extends StatelessWidget { const FirstPage({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("My Second Test App"), backgroundColor: Colors.blue, ), body: Center( child: ElevatedButton( //remember that "() {}" means a function in flutter onPressed: () { //Navigator is the function that makes us be able to //navigate between pages of an app. We "push" a new page. Navigator.of(context).push( //and then the inside has to be like this. //"BuildContext" is like a variable type (such as int or String) //for the different "context"s that acts as a bridge between //different pages. //And our pages are also a type of this BuildContext, //at the very start, //and the return has to be the name of our second page. MaterialPageRoute( builder: (BuildContext context) { return SecondPage(); }, //instead of the {} function space, you can use a "=>" pointer //symbol and write like; //builder: (BuildContext context)=>SecondPage(), //but this is shittier. ), ); }, child: Text("Press me to go to the 2nd page"), ), ), ); } } class SecondPage extends StatefulWidget { const SecondPage({Key? key}) : super(key: key); @override State createState() => _SecondPageState(); } class _SecondPageState extends State { int myindex = 0; bool mybool = true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Center( child: myindex == 0 ? Container( child: Column( children: [ Expanded( child: GestureDetector( child: Image.network( "https://cdn.britannica.com/79/232779-050-6B0411D7/German-Shepherd-dog-Alsatian.jpg", ), onTap: () { setState(() { mybool = !mybool; }); }, ), ), mybool == true ? const Text( "Right now, it is true.", style: TextStyle(fontSize: 16), ) : const Text( "Right now, it is false.", style: TextStyle(fontSize: 16), ), ], ), ) : Container( child: Column( children: [ Expanded( child: GestureDetector( child: Image.network( "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Cat_August_2010-4.jpg/1200px-Cat_August_2010-4.jpg", ), onTap: () { setState(() { mybool = !mybool; }); }, ), ), mybool == true ? const Text( "Right now, it is true.", style: TextStyle(fontSize: 16), ) : const Text( "Right now, it is false.", style: TextStyle(fontSize: 16), ), ], ), ), ), bottomNavigationBar: BottomNavigationBar( items: [ BottomNavigationBarItem( label: "Home", icon: Icon(Icons.home), ), BottomNavigationBarItem( label: "Settings", icon: Icon(Icons.settings), ), ], currentIndex: myindex, onTap: (int index) { setState(() { myindex = index; }); }, ), ); } }