Skip to content

Instantly share code, notes, and snippets.

@nbnD
Created July 5, 2022 07:42
Show Gist options
  • Save nbnD/64705d4104b3ec97302fbfb12ca68cce to your computer and use it in GitHub Desktop.
Save nbnD/64705d4104b3ec97302fbfb12ca68cce to your computer and use it in GitHub Desktop.
Theme Switcher
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:theme_changer/model_theme.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
MyHomePageState createState() => MyHomePageState();
}
class MyHomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Consumer<ModelTheme>(
builder: (context, ModelTheme themeNotifier, child) {
return Scaffold(
appBar: AppBar(
title: Text(themeNotifier.isDark ? "Dark Mode" : "Light Mode"),
actions: [
IconButton(
icon: Icon(themeNotifier.isDark
? Icons.nightlight_round
: Icons.wb_sunny),
onPressed: () {
themeNotifier.isDark
? themeNotifier.isDark = false
: themeNotifier.isDark = true;
})
],
),
body: ListView.builder(
itemCount:5,
itemBuilder: (BuildContext context, int index) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child:const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
style: TextStyle(fontSize: 14),
),
),
);
}),
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment