Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
116083e
Update `simplistic_editor` for Flutter 3.4 beta
bleroux Sep 27, 2022
2c6d412
Re-enable beta and master CI
bleroux Sep 28, 2022
6d41f95
Disable on master
bleroux Oct 10, 2022
04472cf
Added sample code for using plugins and channels from background isol…
gaaclarke Sep 27, 2022
8b76016
goderbauer feedback 1
gaaclarke Sep 27, 2022
5a38e1a
goderbauer feedback2
gaaclarke Sep 27, 2022
48bf57d
goderbauer feedback 3
gaaclarke Sep 27, 2022
15ec99d
Merge branch 'main' of https://github.com/flutter/samples into pr/1448
domesticmouse Jan 10, 2023
84e6010
Add `background_isolate_channels` to CI
domesticmouse Jan 10, 2023
e0c229f
Enable beta CI
domesticmouse Jan 10, 2023
86535c6
Merge branch 'Update_simplistic_editor_to_flutter_3.4' of https://git…
domesticmouse Jan 10, 2023
5915b94
Merge branch 'background-isolate-channels' of https://github.com/gaac…
domesticmouse Jan 10, 2023
c8f096c
Enable all `stable` CI projects
domesticmouse Jan 10, 2023
179b557
`dart fix --apply`
domesticmouse Jan 10, 2023
3dac29e
`print` -> `denugPrint`
domesticmouse Jan 10, 2023
f8222be
Make deps min version not pinned
domesticmouse Jan 10, 2023
d3b52bd
Drop `_isDebug`
domesticmouse Jan 10, 2023
50baef2
Remove unused import
domesticmouse Jan 10, 2023
a1c0e09
`dart format`
domesticmouse Jan 10, 2023
f9e1711
Fixup `linting_tool`
domesticmouse Jan 10, 2023
35c996f
Fixup `form_app`
domesticmouse Jan 10, 2023
eadbf70
Enable all `master` CI
domesticmouse Jan 10, 2023
e38735e
Basic fixes
domesticmouse Jan 10, 2023
b47ef52
Patch `simplistic_editor`
domesticmouse Jan 10, 2023
c7829fe
Fix nl at eol
domesticmouse Jan 10, 2023
895e989
Comment out `simplistic_editor`
domesticmouse Jan 10, 2023
aba70c9
Incorporating @bleroux's latest changes
domesticmouse Jan 10, 2023
d3088f2
Merge branch 'master' of https://github.com/flutter/samples into beta
domesticmouse Jan 14, 2023
335ae38
Clean up CI scripts
domesticmouse Jan 14, 2023
8006222
Copy `experimental/material_3_demo` to top level
domesticmouse Jan 14, 2023
65b1096
Update `game_template`
domesticmouse Jan 18, 2023
92dc66b
Merge branch 'main' of https://github.com/flutter/samples into beta
domesticmouse Jan 18, 2023
0491e1e
Merge branch 'master' of https://github.com/flutter/samples into beta
domesticmouse Jan 21, 2023
4337b32
Update `animations`
domesticmouse Jan 21, 2023
453a6fe
Update `desktop_photo_search`
domesticmouse Jan 21, 2023
9f13e5f
Update `flutter_maps_firestore`
domesticmouse Jan 21, 2023
8375fac
Update `form_app`
domesticmouse Jan 21, 2023
d45b567
Update `infinite_list`
domesticmouse Jan 21, 2023
afaaecd
Update `isolate_example`
domesticmouse Jan 21, 2023
5cfed89
Update `jsonexample`
domesticmouse Jan 21, 2023
a36decc
Update `navigation_and_routing`
domesticmouse Jan 21, 2023
c754b11
Update `place_tracker`
domesticmouse Jan 21, 2023
b414f5a
Update `platform_channels`
domesticmouse Jan 21, 2023
74b57ff
Update `platform_design`
domesticmouse Jan 21, 2023
2a0daae
Update `provider_shopper`
domesticmouse Jan 21, 2023
97246b5
Fixup `context_menus`
domesticmouse Jan 21, 2023
6b2bfdb
`dart format`
domesticmouse Jan 21, 2023
89a26b7
Merge branch 'master' of https://github.com/flutter/samples into beta
domesticmouse Jan 22, 2023
ec101cb
Merge branch 'main' into beta
domesticmouse Jan 23, 2023
238800b
Update the main `material_3_demo`
domesticmouse Jan 23, 2023
a28337b
Merge branch 'main' into beta
domesticmouse Jan 24, 2023
ddcde05
Make `tool/flutter_ci_script_stable.sh` executable again
domesticmouse Jan 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions background_isolate_channels/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../analysis_options.yaml
155 changes: 155 additions & 0 deletions background_isolate_channels/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright 2022 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show Directory;

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart' as path_provider;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uuid/uuid.dart' as uuid;

import 'simple_database.dart';

///////////////////////////////////////////////////////////////////////////////
// This is the UI which will present the contents of the [SimpleDatabase]. To
// see where Background Isolate Channels are used see simple_database.dart.
///////////////////////////////////////////////////////////////////////////////

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Background Isolate Channels',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Background Isolate Channels'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() {
return _MyHomePageState();
}
}

class _MyHomePageState extends State<MyHomePage> {
/// The database that is running on a background [Isolate]. This is nullable
/// because acquiring a [SimpleDatabase] is an asynchronous operation. This
/// value is `null` until the database is initialized.
SimpleDatabase? _database;

/// Local cache of the query results returned by the [SimpleDatabase] for the
/// UI to render from. It is nullable since querying the results is
/// asynchronous. The value is `null` before any result has been received.
List<String>? _entries;

/// What is searched for in the [SimpleDatabase].
String _query = '';

@override
void initState() {
// Write the value to [SharedPreferences] which will get read on the
// [SimpleDatabase]'s isolate. For this example the value is always true
// just for demonstration purposes.
final Future<void> sharedPreferencesSet = SharedPreferences.getInstance()
.then(
(sharedPreferences) => sharedPreferences.setBool('isDebug', true));
final Future<Directory> tempDirFuture =
path_provider.getTemporaryDirectory();

// Wait until the [SharedPreferences] value is set and the temporary
// directory is received before opening the database. If
// [sharedPreferencesSet] does not happen before opening the
// [SimpleDatabase] there has to be a way to refresh
// [_SimpleDatabaseServer]'s [SharedPreferences] cached values.
Future.wait([sharedPreferencesSet, tempDirFuture]).then((values) {
final Directory? tempDir = values[1] as Directory?;
final String dbPath = path.join(tempDir!.path, 'database.db');
SimpleDatabase.open(dbPath).then((database) {
setState(() {
_database = database;
});
_refresh();
});
});
super.initState();
}

@override
void dispose() {
_database?.stop();
super.dispose();
}

/// Performs a find on [SimpleDatabase] with [query] and updates the listed
/// contents.
void _refresh({String? query}) {
if (query != null) {
_query = query;
}
_database!.find(_query).toList().then((entries) {
setState(() {
_entries = entries;
});
});
}

/// Adds a UUID and a timestamp to the [SimpleDatabase].
void _addDate() {
final DateTime now = DateTime.now();
final DateFormat formatter =
DateFormat('EEEE MMMM d, HH:mm:ss\n${const uuid.Uuid().v4()}');
final String formatted = formatter.format(now);
_database!.addEntry(formatted).then((_) => _refresh());
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
children: [
TextField(
onChanged:
_database == null ? null : (query) => _refresh(query: query),
decoration: const InputDecoration(
labelText: 'Search',
suffixIcon: Icon(Icons.search),
),
),
Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
return ListTile(title: Text(_entries![index]));
},
itemCount: _entries?.length ?? 0,
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _database == null ? null : _addDate,
tooltip: 'Add',
child: const Icon(Icons.add),
),
);
}
}
Loading