Skip to content

Instantly share code, notes, and snippets.

@tjharrop
Last active March 19, 2024 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjharrop/b95338349df8050e2ffeb0929576c2c5 to your computer and use it in GitHub Desktop.
Save tjharrop/b95338349df8050e2ffeb0929576c2c5 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Mixed Layouts',
theme: ThemeData(primarySwatch: Colors.blue),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String _content = 'Home page content (flutter)';
Color _themeColor = Colors.red; // Starting theme color
void _updateContent(String page) {
setState(() {
switch (page) {
case 'home':
_content = 'Home page content (flutter)';
_themeColor = Colors.red;
break;
case 'racing':
_content = 'Racing page content';
_themeColor = Colors.blueGrey; // Default color for other pages
break;
case 'sports':
_content = 'Sports page content';
_themeColor = Colors.blueGrey;
break;
case 'register':
_content = 'Register page content (flutter)';
_themeColor = Colors.red;
break;
case 'login':
_content = 'Login page content';
_themeColor = Colors.blueGrey;
break;
default:
_content = 'Default content';
_themeColor = Colors.blueGrey;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: _themeColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildAppBarButton('Home', 'home'),
_buildAppBarButton('Racing', 'racing'),
_buildAppBarButton('Sports', 'sports'),
_buildAppBarButton('Register', 'register'),
_buildAppBarButton('Login', 'login'),
],
),
),
body: Container(
width: double.infinity,
height: double.infinity,
color: _themeColor.withOpacity(0.1),
child: Center(
child: Text(
_content,
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold, color: _themeColor),
),
),
),
);
}
Widget _buildAppBarButton(String label, String page) {
return GestureDetector(
onTap: () => _updateContent(page),
child: Text(
label,
style: TextStyle(color: Colors.white, fontSize: 16),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment