Skip to content

Instantly share code, notes, and snippets.

View chaudharydeepanshu's full-sized avatar
πŸ› οΈ
scope creep

Deepanshu chaudharydeepanshu

πŸ› οΈ
scope creep
View GitHub Profile
@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
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();
}
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 _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
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 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',
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
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
Dart 18 hrs 40 mins β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Šβ–‘ 94.5%
TypeScript 31 mins β–Œβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 2.6%
Ezhil 13 mins ▏░░░░░░░░░░░░░░░░░░░░ 1.2%
JavaScript 10 mins ▏░░░░░░░░░░░░░░░░░░░░ 0.9%
YAML 7 mins ▏░░░░░░░░░░░░░░░░░░░░ 0.7%
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
// Platform messages are asynchronous, so we initialize in an async method.
Future<ConnectivityResult?> initConnectivity(
{required Connectivity connectivity}) async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
return await connectivity.checkConnectivity();