Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
vijaycreations

Vijay R vijayinyoutube

:octocat:
vijaycreations
View GitHub Profile
View alertbox.dart
showDialogBox() => showCupertinoDialog<String>(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: const Text('No Connection'),
content: const Text('Please check your internet connectivity'),
actions: <Widget>[
TextButton(
onPressed: () async {
Navigator.pop(context, 'Cancel');
setState(() => isAlertSet = false);
View homepage.dart
late StreamSubscription subscription;
bool isDeviceConnected = false;
bool isAlertSet = false;
@override
void initState() {
getConnectivity();
super.initState();
}
View ui.dart
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Connectivity Checker'),
),
body: Center(
child: ElevatedButton(
onPressed: () => Navigator.push(
context,
View home_page_ui_2.dart
body: Center(
child: ElevatedButton(
onPressed: () async {
await homePageData.saveJsonData(rawData);
homePageData.getJsonData();
},
child: const Text('Save Data'),
),
),
View shared_pref.dart
class HomePageData {
Future saveJsonData(jsonData) async {
final prefs = await SharedPreferences.getInstance();
var saveData = jsonEncode(jsonData);
await prefs.setString('jsonData', saveData);
}
Future<void> getJsonData() async {
final prefs = await SharedPreferences.getInstance();
var temp = prefs.getString('jsonData') ?? jsonEncode(defaultData);
View raw_data.dart
final rawData = <String, dynamic>{'name': 'Alice', 'age': 20};
final defaultData = <String, dynamic>{
'name': 'name not found.',
'age': 00,
};
View home_page_model.dart
class HomePageModel {
final String name;
final int? age;
HomePageModel(
this.name,
this.age,
);
View home_page_ui.dart
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ElevatedButton(
onPressed: () {},
child: const Text('Save Data'),
View function.dart
Future<void> _changeOpacity() async {
setState(() => _visible = !_visible);
await Future.delayed(const Duration(milliseconds: 650));
setState(() => showPayBtn = !showPayBtn);
setState(() => _visible = !_visible);
}
View animated_opacity.dart
AnimatedOpacity(
opacity: _visible ? 1.0 : 0.0,
duration: const Duration(milliseconds: 650),
child: ElevatedButton(
...
),
),