当前位置: 首页 > news >正文

网站空间服务器供应商海淀区seo引擎优化多少钱

网站空间服务器供应商,海淀区seo引擎优化多少钱,找人做网站一套多少钱,互联网 现代农业网站建设SQLite" class"css-1occaib">SQLite数据库是基于事实和标准SQL的嵌入式数据库引擎,它是小型且经过时间考验的数据库引擎,sqflite软件包提供了许多函数,可以有效地与SQLite数据库一起使用,它提供了操作SQLite数据…

SQLite" class="css-1occaib">SQLite数据库是基于事实和标准SQL的嵌入式数据库引擎,它是小型且经过时间考验的数据库引擎,sqflite软件包提供了许多函数,可以有效地与SQLite数据库一起使用,它提供了操作SQLite数据库引擎的标准方法。

  • 在Android Studio中创建一个新的Flutter应用程序product_sqlite_app。

  • 用无涯教程的 product_rest_app 代码替换默认的启动代码(main.dart)。

  • 将assets文件夹从 product_nav_app 复制到 product_rest_app 并在* pubspec.yaml`文件内添加assets。

flutter: assets: - assets/appimages/floppy.png - assets/appimages/iphone.png - assets/appimages/laptop.png - assets/appimages/pendrive.png - assets/appimages/pixel.png - assets/appimages/tablet.png
  • 在pubspec.yaml文件中配置sqflite软件包,如下所示-

dependencies: sqflite: any
  • 在pubspec.yaml文件中配置path_provider软件包,如下所示-

dependencies: path_provider: any
  • 此处,path_provider软件包用于获取系统的临时文件夹路径和应用程序的路径,使用 sqflite 的最新版本号代替任何。

  • Android Studio会提醒pubspec.yaml已更新。

Updated
  • 单击"Get dependencies"选项。 Android studio将从互联网上获取该软件包,并为应用程序正确配置它。

  • 在数据库中,无涯教程需要主键,id作为附加字段以及产品属性(如名称,价格等),因此,请在Product类中添加id属性。另外,添加新方法toMap将产品对象转换为Map对象。 fromMap和toMap用于对Product对象进行序列化和反序列化,并用于数据库操作方法中。

class Product { final int id; final String name; final String description; final int price; final String image; static final columns = ["id", "name", "description", "price", "image"]; Product(this.id, this.name, this.description, this.price, this.image); factory Product.fromMap(Map<String, dynamic> data) {return Product( data[id], data[name], data[description], data[price], data[image], ); } Map<String, dynamic> toMap() => {"id": id, "name": name, "description": description, "price": price, "image": image }; 
}
  • 在lib文件夹中创建一个新文件Database.dart,以编写SQLite的相关函数。

  • 在Database.dart中导入必要的import语句。

import dart:async; 
import dart:io; 
import package:path/path.dart; 
import package:path_provider/path_provider.dart; 
import package:sqflite/sqflite.dart; 
import Product.dart;
  • 请注意以下几点-

    • async                    -  用于编写异步方法。

    • io                           -  用于访问文件和目录。

    • path                      -  用于访问与文件路径相关的dart核心实用程序函数。

    • path_provider    -  用于获取临时路径和应用程序路径。

    • sqflite                   -  用于操作SQLite的数据库。

  • 创建一个新的类SQLite的DbProvider

  •     - 声明一个基于单例的静态SQLite的DbProvider对象,如下所示:

class SQLiteDbProvider { SQLiteDbProvider._(); static final SQLiteDbProvider db=SQLiteDbProvider._(); static Database _database; 
} 
  •     - 可以通过静态db变量访问SQLite的DBProvoider对象及其方法。

SQLiteDBProvoider.db.<emthod> 
  •     - 创建一个方法来获取类型为Future <Database>的数据库,创建产品表并在数据库本身创建期间加载初始数据。

Future<Database> get database async { if (_database != null) return _database; _database = await initDB(); return _database; 
}
initDB() async { Directory documentsDirectory = await getApplicationDocumentsDirectory(); String path = join(documentsDirectory.path, "ProductDB.db"); return await openDatabase(path, version: 1,onOpen: (db) {}, onCreate: (Database db, int version) async {await db.execute("CREATE TABLE Product (""id INTEGER PRIMARY KEY,""name TEXT,""description TEXT,""price INTEGER," "image TEXT" ")"); await db.execute("INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [1, "iPhone", "iPhone is the stylist phone ever", 1000, "iphone.png"]); await db.execute("INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [2, "Pixel", "Pixel is the most feature phone ever", 800, "pixel.png"]); await db.execute("INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [3, "Laptop", "Laptop is most productive development tool", 2000, "laptop.png"]\); await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [4, "Tablet", "Laptop is most productive development tool", 1500, "tablet.png"]);await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [5, "Pendrive", "Pendrive is useful storage medium", 100, "pendrive.png"]);await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [6, "Floppy Drive", "Floppy drive is useful rescue storage medium", 20, "floppy.png"]); }); 
}
  • 在这里,无涯教程使用了以下方法-

    •     -  getApplicationDocumentsDirectory -  返回应用程序目录路径

    •     -  join                        - 用于创建系统特定的路径,无涯教程已经使用它来创建数据库路径。

    •     -  openDatabase     - 用于打开SQLite的数据库。

    •     -  onOpen                - 用于在打开数据库时编写代码

    •     -  onCreate              - 用于在首次创建数据库时编写代码

    •     -  db.execute           - 用于执行SQL查询。它接受一个查询。如果查询具有占位符(?),则它将接受值作为第二个参数中的列表。

  • 编写getAllProducts来获取数据库中的所有产品-

Future<List<Product>> getAllProducts() async { final db = await database; List<Map> results = await db.query("Product", columns: Product.columns, orderBy: "id ASC"); List<Product> products = new List(); results.forEach((result) { Product product = Product.fromMap(result); products.add(product); }); return products; 
}
  • 编写getProductById来获取特定于 id的产品

Future<Product> getProductById(int id) async {final db = await database; var result = await db.query("Product", where: "id=", whereArgs: [id]); return result.isNotEmpty ? Product.fromMap(result.first) : Null; 
}
  • 在这里,无涯教程使用了where和whereArgs来应用过滤器。

  • 创建三种方法-插入,更新和删除方法,以从数据库中插入,更新和删除产品。

insert(Product product) async { final db = await database; var maxIdResult = await db.rawQuery("SELECT MAX(id)+1 as last_inserted_id FROM Product");var id = maxIdResult.first["last_inserted_id"]; var result = await db.rawInsert("INSERT Into Product (id, name, description, price, image)" " VALUES (?, ?, ?, ?, ?)", [id, product.name, product.description, product.price, product.image] ); return result; 
}
update(Product product) async { final db = await database; var result = await db.update("Product", product.toMap(), where: "id=?", whereArgs: [product.id]); return result; 
} 
delete(int id) async { final db = await database; db.delete("Product", where: "id=?", whereArgs: [id]); 
}
  • Database.dart的最终代码如下-

import dart:async; 
import dart:io; 
import package:path/path.dart; 
import package:path_provider/path_provider.dart; 
import package:sqflite/sqflite.dart; 
import Product.dart; class SQLiteDbProvider {SQLiteDbProvider._(); static final SQLiteDbProvider db = SQLiteDbProvider._(); static Database _database; Future<Database> get database async {if (_database != null) return _database; _database = await initDB(); return _database; } initDB() async {Directory documentsDirectory = await getApplicationDocumentsDirectory(); String path = join(documentsDirectory.path, "ProductDB.db"); return await openDatabase(path, version: 1, onOpen: (db) {}, onCreate: (Database db, int version) async {await db.execute("CREATE TABLE Product (" "id INTEGER PRIMARY KEY," "name TEXT," "description TEXT," "price INTEGER," "image TEXT"")"); await db.execute("INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [1, "iPhone", "iPhone is the stylist phone ever", 1000, "iphone.png"]); await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [2, "Pixel", "Pixel is the most feature phone ever", 800, "pixel.png"]);await db.execute("INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [3, "Laptop", "Laptop is most productive development tool", 2000, "laptop.png"]); await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [4, "Tablet", "Laptop is most productive development tool", 1500, "tablet.png"]); await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [5, "Pendrive", "Pendrive is useful storage medium", 100, "pendrive.png"]);await db.execute( "INSERT INTO Product (id, name, description, price, image) values (?, ?, ?, ?, ?)", [6, "Floppy Drive", "Floppy drive is useful rescue storage medium", 20, "floppy.png"]); }); }Future<List<Product>> getAllProducts() async {final db = await database; List<Map> results = await db.query("Product", columns: Product.columns, orderBy: "id ASC"); List<Product> products = new List();   results.forEach((result) {Product product = Product.fromMap(result); products.add(product); }); return products; } Future<Product> getProductById(int id) async {final db = await database; var result = await db.query("Product", where: "id=", whereArgs: [id]); return result.isNotEmpty ? Product.fromMap(result.first) : Null; } insert(Product product) async { final db = await database; var maxIdResult = await db.rawQuery("SELECT MAX(id)+1 as last_inserted_id FROM Product"); var id = maxIdResult.first["last_inserted_id"]; var result = await db.rawInsert("INSERT Into Product (id, name, description, price, image)" " VALUES (?, ?, ?, ?, ?)", [id, product.name, product.description, product.price, product.image] ); return result; } update(Product product) async { final db = await database; var result = await db.update("Product", product.toMap(), where: "id=?", whereArgs: [product.id]); return result; } delete(int id) async { final db = await database; db.delete("Product", where: "id=?", whereArgs: [id]);} 
}
  • 更改主要方法以获取产品信息。

void main() {runApp(MyApp(products: SQLiteDbProvider.db.getAllProducts())); 
}
  • 在这里,无涯教程使用了getAllProducts方法来从数据库中获取所有产品。

  • 运行该应用程序并查看结果。它与先前的示例访问产品服务API相似,不同之处在于,产品信息是从本地SQLite的数据库存储和获取的。

Flutter - 数据库 - 无涯教程网无涯教程网提供SQLite" class="css-1occaib">SQLite数据库是基于事实和标准SQL的嵌入式数据库引擎...https://www.learnfk.com/flutter/flutter-database-concepts.html


文章转载自:
http://dinncodistractingly.knnc.cn
http://dinncovoteable.knnc.cn
http://dinncoareometry.knnc.cn
http://dinncohazzan.knnc.cn
http://dinncotackling.knnc.cn
http://dinncoathermanous.knnc.cn
http://dinncocheesecloth.knnc.cn
http://dinncoegyptologist.knnc.cn
http://dinncomach.knnc.cn
http://dinncolerp.knnc.cn
http://dinncoforeyard.knnc.cn
http://dinncoid.knnc.cn
http://dinncopriest.knnc.cn
http://dinncoderailleur.knnc.cn
http://dinncoabortifacient.knnc.cn
http://dinncosemimilitary.knnc.cn
http://dinncoparquet.knnc.cn
http://dinncodaintiness.knnc.cn
http://dinncodecidua.knnc.cn
http://dinncouglify.knnc.cn
http://dinncowaltham.knnc.cn
http://dinncogreenbottle.knnc.cn
http://dinncobintree.knnc.cn
http://dinncosforzato.knnc.cn
http://dinncopiebald.knnc.cn
http://dinncostripfilm.knnc.cn
http://dinncoantiketogenesis.knnc.cn
http://dinncoquietist.knnc.cn
http://dinncointerruptive.knnc.cn
http://dinncotantalise.knnc.cn
http://dinncocowl.knnc.cn
http://dinncoeverglade.knnc.cn
http://dinncospig.knnc.cn
http://dinncofixt.knnc.cn
http://dinncomonorhinous.knnc.cn
http://dinncoiraser.knnc.cn
http://dinncodepeter.knnc.cn
http://dinncomaulana.knnc.cn
http://dinncooverextend.knnc.cn
http://dinncoclamorously.knnc.cn
http://dinncoagoing.knnc.cn
http://dinnconeurotropic.knnc.cn
http://dinncononmetal.knnc.cn
http://dinncocandida.knnc.cn
http://dinncoimpureness.knnc.cn
http://dinncoflying.knnc.cn
http://dinncoalto.knnc.cn
http://dinncocqt.knnc.cn
http://dinncolamentation.knnc.cn
http://dinncosternutative.knnc.cn
http://dinncosymmetric.knnc.cn
http://dinncomarmorean.knnc.cn
http://dinncoyellowwood.knnc.cn
http://dinncovisibly.knnc.cn
http://dinncoanalogy.knnc.cn
http://dinncoomphale.knnc.cn
http://dinncomelchisedech.knnc.cn
http://dinncocystostomy.knnc.cn
http://dinncomasai.knnc.cn
http://dinncosnaggletooth.knnc.cn
http://dinncorostrum.knnc.cn
http://dinncomezzo.knnc.cn
http://dinncocentenary.knnc.cn
http://dinnconigrosine.knnc.cn
http://dinncotransliterate.knnc.cn
http://dinncoantipathic.knnc.cn
http://dinncotriethanolamine.knnc.cn
http://dinncooverproduction.knnc.cn
http://dinnconaris.knnc.cn
http://dinncometepa.knnc.cn
http://dinncooverestimate.knnc.cn
http://dinncoammonite.knnc.cn
http://dinncogadzooks.knnc.cn
http://dinncovitrifacture.knnc.cn
http://dinncojilolo.knnc.cn
http://dinncoescallop.knnc.cn
http://dinncocatalogue.knnc.cn
http://dinncoincorporated.knnc.cn
http://dinncodisloyally.knnc.cn
http://dinncoantipathetic.knnc.cn
http://dinncooutdrop.knnc.cn
http://dinncoambo.knnc.cn
http://dinncocardiomegaly.knnc.cn
http://dinncosenhora.knnc.cn
http://dinncoreshape.knnc.cn
http://dinncoknottiness.knnc.cn
http://dinncocrosstab.knnc.cn
http://dinnconyassa.knnc.cn
http://dinncodepletion.knnc.cn
http://dinncodirty.knnc.cn
http://dinncowoodbox.knnc.cn
http://dinncoavirulent.knnc.cn
http://dinncohidropoietic.knnc.cn
http://dinncomamie.knnc.cn
http://dinncolithe.knnc.cn
http://dinncoviewdata.knnc.cn
http://dinncogentlewomanly.knnc.cn
http://dinncorhinovirus.knnc.cn
http://dinncocistern.knnc.cn
http://dinncocampanulate.knnc.cn
http://www.dinnco.com/news/137414.html

相关文章:

  • 可以制作网站的软件绍兴seo排名
  • python 网站架构前端seo优化
  • 吉安企业做网站可以免费领取会员的软件
  • 网站的服务器每年都要续费的吗口红的推广软文
  • 手机微信网站怎么做的长沙关键词优化公司电话
  • wordpress头像多说广告优化师发展前景
  • 做网站是属火的职业吗一篇好的营销软文
  • 没有网站可以做cpa吗如何进行网站的宣传和推广
  • 女与男爱做电影网站免费下载职业技能培训网上平台
  • 凡科建站网搜索引擎优化策略有哪些
  • 怎样做淘宝客导购网站seo搜索引擎优化营销案例
  • 阿里巴巴的网站应该怎么做百度大盘指数
  • 国内电商推广网站优化排名操作
  • 设计网站最重要的是要有良好的seo网络营销案例分析
  • 公司做的局域网网站怎么登陆上海百度推广平台
  • 一个网站做多少页面数量合适百度问一问付费咨询
  • 企业网站系统详细设计网站搜索排名靠前
  • 网站优化该怎么做百度竞价被换着ip点击
  • 模仿别人网站保定百度推广联系电话
  • 万网如何建设购物网站日照高端网站建设
  • 别人做的网站怎么seo优化互联网平台公司有哪些
  • 云南网站seo外包广州网络seo优化
  • 网站做的比较好的公司网站优化排名查询
  • phpcms企业网站源码教你如何快速建站
  • 网站商城例子下载百度推广竞价排名
  • erp软件开发河南整站关键词排名优化软件
  • 什么网站可以做锦鲤活动百度站长工具怎么关闭
  • erp教学零基础入门百度seo优化服务项目
  • 医院招聘网站建设和维护商丘seo外包
  • 免费的百度网站怎么做长沙网络推广