This file contains hidden or 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:hive/hive.dart'; | |
| part 'data_model.g.dart'; | |
| @HiveType(typeId: 0) | |
| class DataModel extends HiveObject{ | |
| @HiveField(0) | |
| final String? item; | |
| @HiveField(1) | |
| final int? quantity; |
This file contains hidden or 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
| showModalBottomSheet( | |
| context: context, | |
| builder: (context) { | |
| return Scaffold( //scaffold provides us the ability to show snackbar in the modal bottom sheet | |
| body: Column( | |
| mainAxisSize: MainAxisSize.min, | |
| children: [ | |
| const ListTile( | |
| leading: Icon(Icons.person), | |
| title: Text("Profile"), |
This file contains hidden or 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
| if(pickedDate != null ){ | |
| print(pickedDate); //get the picked date in the format => 2022-07-04 00:00:00.000 | |
| String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate); // format date in required form here we use yyyy-MM-dd that means time is removed | |
| print(formattedDate); //formatted date output using intl package => 2022-07-04 | |
| //You can format date as per your need | |
| setState(() { | |
| dateController.text = formattedDate; //set foratted date to TextField value. | |
| }); | |
| }else{ |
This file contains hidden or 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
| TextField( | |
| controller: dateController, //editing controller of this TextField | |
| decoration: const InputDecoration( | |
| icon: Icon(Icons.calendar_today), //icon of text field | |
| labelText: "Enter Date" //label text of field | |
| ), | |
| readOnly: true, // when true user cannot edit text | |
| onTap: () async { | |
| //when click we have to show the datepicker | |
| } |
This file contains hidden or 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'; | |
| import 'package:theme_changer/model_theme.dart'; | |
| class HomePage extends StatefulWidget { | |
| const HomePage({Key? key}) : super(key: key); | |
| @override | |
| MyHomePageState createState() => MyHomePageState(); | |
| } |
This file contains hidden or 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'; | |
| import 'package:theme_changer/model_theme.dart'; | |
| import 'homepage.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } |
This file contains hidden or 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 'mytheme_preference.dart'; | |
| class ModelTheme extends ChangeNotifier { | |
| late bool _isDark; | |
| late MyThemePreferences _preferences; | |
| bool get isDark => _isDark; | |
| ModelTheme() { | |
| _isDark = false; |
This file contains hidden or 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:shared_preferences/shared_preferences.dart'; | |
| class MyThemePreferences { | |
| static const THEME_KEY = "theme_key"; | |
| setTheme(bool value) async { | |
| SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); | |
| sharedPreferences.setBool(THEME_KEY, value); | |
| } |
This file contains hidden or 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
| static Future<List<Map<String, dynamic>>> getItems() async { | |
| final db = await DatabaseHelper.db(); | |
| return db.query('items', orderBy: "id"); | |
| } |
This file contains hidden or 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
| static Future<int> createItem(String? title, String? descrption) async { | |
| final db = await DatabaseHelper.db(); | |
| final data = {'title': title, 'description': descrption}; | |
| final id = await db.insert('items', data, | |
| conflictAlgorithm: sql.ConflictAlgorithm.replace); | |
| return id; | |
| } |