Skip to content

Instantly share code, notes, and snippets.

View chaudharydeepanshu's full-sized avatar
🎯
New Journey

Deepanshu Chaudhary chaudharydeepanshu

🎯
New Journey
View GitHub Profile
import 'package:shared_preferences/shared_preferences.dart';
Future<int?> retrieveSavedThemeMode() async {
final prefs = await SharedPreferences.getInstance();
// Check where the name is saved before or not
if (!prefs.containsKey('savedThemeModeIndex')) {
//if not return zero for ThemeMode.System
return 0;
}
//else return the saved theme
import 'package:flutter/material.dart';
import 'package:flutter_dark_mode_demo/sharedPreferences/app_theme_shared_preferences.dart';
Future<void> main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
int? retrieveSavedThemeModeIndex = await retrieveSavedThemeMode();
final ThemeMode savedThemeMode = retrieveSavedThemeModeIndex == 0
? ThemeMode.system
: retrieveSavedThemeModeIndex == 1
? ThemeMode.light
class MyApp extends StatelessWidget {
const MyApp({Key? key, this.savedThemeMode}) : super(key: key);
final ThemeMode? savedThemeMode;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
class MyApp extends StatefulWidget {
const MyApp({Key? key, this.savedThemeMode}) : super(key: key);
final ThemeMode? savedThemeMode;
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
class _MyAppState extends State<MyApp> {
//Keeps track of theme
late ThemeMode? themeMode = widget.savedThemeMode;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
//Add themeMode as themeMode
import 'package:flutter/material.dart';
class CustomDrawer extends StatefulWidget {
const CustomDrawer({
Key? key,
required this.themeMode,
required this.onThemeMode,
}) : super(key: key);
final ThemeMode? themeMode;
final ValueChanged<ThemeMode>? onThemeMode;
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, this.themeMode, this.onThemeMode})
: super(key: key);
final ThemeMode? themeMode; //
final ValueChanged<ThemeMode>? onThemeMode; //
@override
State<MyHomePage> createState() => _MyHomePageState();
}
@chaudharydeepanshu
chaudharydeepanshu / main.dart
Last active August 5, 2022 14:20
data_grid_jank_example
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
@chaudharydeepanshu
chaudharydeepanshu / main.dart
Created August 4, 2022 23:57
inserting more data on start of scrollview on swiping top
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@chaudharydeepanshu
chaudharydeepanshu / main.dart
Created August 5, 2022 10:11
scroll view issue for calendar view
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);