Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
vijaycreations

Vijay R vijayinyoutube

:octocat:
vijaycreations
View GitHub Profile
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(
...
),
),
View elevated_btn.dart
ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 0,
primary: primaryColor,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
child: Text(
View cascade.dart
void main() {
Student()
..name = 'Alice'
..id = 'A01'
..method1()
..method2();
}
View main.dart
void main() {
Student student = Student();
student.name='Alice';
student.id='A01';
student.method1();
student.method2();
}