Skip to content

Instantly share code, notes, and snippets.

View CodingWithTashi's full-sized avatar
💭
Code For Life

Kunchok Tashi CodingWithTashi

💭
Code For Life
View GitHub Profile
floatingActionButton: FloatingActionButton(
onPressed: counterProvider.update,
tooltip: 'Increment',
child: const Icon(Icons.add),
)
CounterProvider counterProvider = Provider.of<CounterProvider>(context, listen: false); //make sure to put listent to false
const Text(
'You have pushed the button this many times:',
),
Consumer<CounterProvider>(
builder: (_, provider, __) {
return Text(
'${provider.count}',
style: Theme.of(context).textTheme.headline4,
);
},
return ChangeNotifierProvider<CounterProvider>(
create: (context) => CounterProvider(),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
),
);
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
///THIS CLASS IS WHERE STATE ARE BEING MANAGE,EVERYTIME WE CALL update(), IT WILL INFORM
///TEXT WIDGET TO REBUILD
class CounterProvider extends ChangeNotifier {
int count = 0;
update() {
count++;
notifyListeners();
}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
void main() {
String? data;
String newData = data!+"!!!";
}
void main() {
List<String>? firstList;
List<String> secondList=['a','b','c'];
List<String> finalList = [...?firstList,...secondList];
print(finalList);
}
void main() {
String? temporaryValue;
String newValue = temporaryValue??='Test';
print(newValue);
}
void main() {
String? temporaryValue;
//temporaryValue='Initial Temp Value';
String newValue = temporaryValue??'Test';
print(newValue);
}