Last active
December 5, 2023 12:25
-
-
Save alefwd/6389ad8e8ca63104e46506bba930a2fd to your computer and use it in GitHub Desktop.
Can't compile two app bars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: (34 % 3 == 0) ? AleAppBar1() : AleAppBar2(), | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class AleAppBar1 extends StatelessWidget implements PreferredSizeWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AppBar(title: const Text('AleAppBar1'),); | |
} | |
@override | |
Size get preferredSize => const Size.fromHeight(kToolbarHeight); | |
} | |
class AleAppBar2 extends StatelessWidget implements PreferredSizeWidget { | |
@override | |
Widget build(BuildContext context) { | |
return AppBar(title: const Text('AleAppBar2'),); | |
} | |
@override | |
Size get preferredSize => const Size.fromHeight(kToolbarHeight); | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Text( | |
'Hello, World!', | |
style: Theme.of(context).textTheme.headlineMedium, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment