I'm trying to create a Material design app without the Scaffold element: Here is the purely default app:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Text(widget.title);
}
}
The result is:
How to fix that and use material styles without Scaffold?
Answer:
I need to use the Material
widget. As a very beginner in Flutter I had read Material design tutorials and all of them were using the Scaffold
widget. Thanks for pointing out the Material
widget in comments.
primarySwatch: Colors.blue,
to take effect you have to useScaffold
- seematerial/scaffold.dart
source file, line ~2111 (in version 1.10.15) where theme is read and then in line 2323 is setMaterial.color
- what is wrong with using "bare"Scaffold
?Scaffold
usesMatarial
widget