This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
floatingActionButton: FloatingActionButton( | |
onPressed: counterProvider.update, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CounterProvider counterProvider = Provider.of<CounterProvider>(context, listen: false); //make sure to put listent to false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Text( | |
'You have pushed the button this many times:', | |
), | |
Consumer<CounterProvider>( | |
builder: (_, provider, __) { | |
return Text( | |
'${provider.count}', | |
style: Theme.of(context).textTheme.headline4, | |
); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return ChangeNotifierProvider<CounterProvider>( | |
create: (context) => CounterProvider(), | |
child: MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String? data; | |
String newData = data!+"!!!"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
List<String>? firstList; | |
List<String> secondList=['a','b','c']; | |
List<String> finalList = [...?firstList,...secondList]; | |
print(finalList); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String? temporaryValue; | |
String newValue = temporaryValue??='Test'; | |
print(newValue); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
String? temporaryValue; | |
//temporaryValue='Initial Temp Value'; | |
String newValue = temporaryValue??'Test'; | |
print(newValue); | |
} |
NewerOlder