Skip to content

Instantly share code, notes, and snippets.

@FantasyCheese
FantasyCheese / main.dart
Last active September 18, 2020 09:46
Simplest InheritedWidget Example
import 'package:flutter/material.dart';
void main() {
runApp(CountProvider(
count: 42,
child: MyApp(),
));
}
class CountProvider extends InheritedWidget {
@FantasyCheese
FantasyCheese / main.dart
Last active September 18, 2020 10:10
Simplest InheritedWidget with State Update Example
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(CounterUpdater(
child: MyApp(),
));
}
@FantasyCheese
FantasyCheese / main.dart
Created September 18, 2020 11:24
Simplest Provider with ChangeNotifier Example
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(ChangeNotifierProvider(
create: (_) => Counter(),
child: MyApp(),
));
@FantasyCheese
FantasyCheese / main.dart
Created September 18, 2020 11:57
Simplest MultiProvider Example
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => Counter()),
ChangeNotifierProvider(create: (_) => Clock())
@FantasyCheese
FantasyCheese / main.dart
Last active September 15, 2024 09:49
Simplest Riverpod Example
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/all.dart';
final countProvider = StateProvider((ref) => 0); // declare providers anywhere
final clockProvider = StateProvider((ref) => DateTime.now());
void main() {
runApp(ProviderScope(child: MyApp())); // add ProviderScope at top level
}
@FantasyCheese
FantasyCheese / main.dart
Last active September 18, 2020 15:21
Simplest Riverpod without Flutter Example
import 'dart:async';
import 'package:flutter_riverpod/all.dart';
final container = ProviderContainer(); // declare global ProviderContainer
final countProvider = StateProvider((ref) => 0); // declare providers anywhere
void main() {
final ProviderSubscription<StateController<int>> subscription = container.listen(countProvider, didChange: (sub) { // listen from container
print(sub.read().state);
@FantasyCheese
FantasyCheese / main.dart
Last active September 23, 2020 15:33
Pacman in Flutter
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';
const originalMap = [
[1,1,1,1,1,1,1,1,1,1,1,],
[1,0,0,0,0,0,0,0,0,0,1,],
[1,0,1,0,1,0,1,0,1,0,1,],
[1,0,1,0,1,1,1,0,1,0,1,],
[1,0,1,0,0,0,0,0,1,0,1,],
@FantasyCheese
FantasyCheese / main.dart
Created June 9, 2021 17:55
Radio Group
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
final doubleListQueue = ["personalName", "carrierType", "email"];
final tripleListQueue = ["companyName", "taxID", "email"];
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Text("Please help me!!!"),
),
),
@FantasyCheese
FantasyCheese / main.dart
Created July 2, 2021 08:56
Flutter slider minimum
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: App(),
),
);
}