Reputation: 2165
I need to change the flutter theme color, but when I tried then run my app it's show nothing to change. I don't know why.
I have tried this way:
import 'package:flutter/material.dart';
import 'pages/home_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
themeMode: ThemeMode.dark,
theme: ThemeData(primarySwatch: Colors.deepPurple),
darkTheme: ThemeData(
brightness: Brightness.dark, primarySwatch: Colors.deepPurple),
);
}
}
when I change like this way, then still show me default blue color.
flutter version: 2.2.1
Any suggestion please.
Upvotes: 0
Views: 4946
Reputation: 2073
with this code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Title",
theme: ThemeData(primarySwatch: Colors.deepPurple),
darkTheme: ThemeData(
brightness: Brightness.dark, primarySwatch: Colors.deepPurple),
home: Test(),
);
}
}
class Test extends StatelessWidget {
const Test({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SomeText"),
),
body: Center(child: Text("Center Text",)),
);
}
}
I get This result. (Flutter 1.22.5)
Upvotes: 3