我正在尝试创建一个可在我的应用程序中的所有页面访问的统一抽屉.如何在所有这些页面中保持它,而不必在每个dart文件中重新创建我的自定义Drawer小部件?
如何在长文本小部件内创建换行符?
例如,我正在创建有关我自己的传记页面。我想展示三段。但是目前,我正在一个大型Text Widget中输出这些段落,并且输出中没有换行符以区分这些段落。我怎样才能做到这一点?
我希望能够在已经填充的本地 sqlite 数据库中收藏/标记项目,以显示在显示收藏项目列表的“收藏夹页面”上。
在这个 sqlite 数据库中,我有一个流派表和一个与特定流派相关的书籍表。我没有使用模型“书籍”类在列表中显示书籍信息。我使用 rawQuery 将书籍信息的 ROW 放入 List 中,以在 bookView 页面中显示该书籍信息。像这样..
Future getDescriptionData() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "asset_sample_sqlite.db");
ByteData data =
await rootBundle.load(join("assets", "sample_sqlite.db"));
List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await new File(path).writeAsBytes(bytes);
Database db = await openDatabase(path);
await db
.rawQuery('SELECT * FROM books WHERE id = "${widget.id}"') // id passed on from previous page where it shows a list of books
.then((results) {
setState(() {
loading = false;
initialized = …Run Code Online (Sandbox Code Playgroud) 我有一个白色的 AppBar 颜色,当我将 AppDrawer 添加到抽屉的图标时,它会与白色的 AppBar 混合在一起。如何更改抽屉图标的颜色?
这是我的一些代码:
@override
Widget build(BuildContext context) {
return Scaffold(
endDrawer: AppDrawer(),
appBar: AppBar(
backgroundColor: Colors.white,
title: Image.asset(
'images/appbar_logo.jpg',
fit: BoxFit.fill,
),
centerTitle: true,
), // AppBar
Run Code Online (Sandbox Code Playgroud)
和我的 AppDrawer 有状态小部件:
class AppDrawer extends StatefulWidget {
@override
_AppDrawerState createState() => _AppDrawerState();
}
class _AppDrawerState extends State<AppDrawer> {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
children: <Widget>[
new DrawerHeader(
child: new Image.asset("images/drawer_header_img.jpg")),
ListTile(
title: new Text("Item 1"),
),
ListTile(
title: new Text("Item 2"),
),
], …Run Code Online (Sandbox Code Playgroud) 如何使用 TextField 小部件作为搜索栏来查询本地 SQLite 数据库资产的结果?
还有比使用文本字段小部件更好的选择吗?例子将非常感激。
用代码编辑:
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.all(8.0),
child: new Container(
height: 70.0,
color: Theme.CompanyColors.iBlue,
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Card(
child: new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Icon(Icons.search),
new Container(
width: MediaQuery.of(context).size.width - 100.0,
child: new TextField(
decoration: InputDecoration(
hintText: 'Search',
//onChanged:
//onSearchTextChanged,
),
),
),
Run Code Online (Sandbox Code Playgroud)
这是搜索栏的代码
我的数据库有一个附有paragraph_id的表句子,所以我想通过这样的查询进行搜索
select * from sentences where title or body = userinput%
Run Code Online (Sandbox Code Playgroud)