Step 1
We cannot directly remove the time stamp from Dynamic Light And Dark Theme but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dynamic_theme: ^1.0.0
flutter pub get
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:dynamic_theme/theme_switcher_widgets.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:dynamic_theme/theme_switcher_widgets.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicTheme(
defaultBrightness: Brightness.light,
data: (brightness) => ThemeData(
primarySwatch: Colors.indigo,
brightness: brightness,
),
themedWidgetBuilder: (context, theme) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: theme,
home: MyHomePage(),
);
});
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text("Light & Dark Theme"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
color: Colors.indigo,
onPressed: changeBrightness,
child: const Text("Change Brightness",style: TextStyle(color: Colors.white),),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: showChooser,
child: const Icon(Icons.add),
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.insert_drive_file), title: Text("File")),
BottomNavigationBarItem(
icon: Icon(Icons.show_chart), title: Text("Chart")),
],
),
);
}
void showChooser() {
showDialog<void>(
context: context,
builder: (context) {
return BrightnessSwitcherDialog(
onSelectedTheme: (brightness) {
DynamicTheme.of(context).setBrightness(brightness);
},
);
});
}
void changeBrightness() {
DynamicTheme.of(context).setBrightness(
Theme.of(context).brightness == Brightness.dark
? Brightness.light
: Brightness.dark);
}
void changeColor() {
DynamicTheme.of(context).setThemeData(ThemeData(
primaryColor: Theme.of(context).primaryColor == Colors.indigo ? Colors.red : Colors.indigo));
}
}