build method
- BuildContext context
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
context
using BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
String name = '';
if (webId.isNotEmpty) {
name = getNameFromWebId(webId);
} else {
name = 'Not logged in';
}
return Drawer(
shape: Border(),
child: ListView(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
children: <Widget>[
Container(
padding: EdgeInsets.only(
top: 24 + MediaQuery.of(context).padding.top,
bottom: 24,
),
decoration: const BoxDecoration(
color: darkGreen,
),
child: Column(
children: [
const CircleAvatar(
radius: 55,
backgroundImage: AssetImage('assets/images/avatar.png'),
),
const SizedBox(
height: 12,
),
Text(
name,
style: const TextStyle(color: backgroundWhite, fontSize: 25),
),
Container(
padding: const EdgeInsets.all(10),
child: Text(
webId,
style:
const TextStyle(color: backgroundWhite, fontSize: 14),
),
),
Container(
padding: const EdgeInsets.all(10),
child: VersionWidget(
version: appVersion,
changelogUrl:
// Currently (VersionWidget version 1.0.3) for the chrome/web
// deployment the first URL below results in CORS blocking while
// the second works. However the second renders raw text when
// tapped while the first renders the Markdown which is a whole
// lot nicer. So with the first on chrome/web the version
// checking does not work. (20250717 gjw)
'https://github.com/anusii/notepod/blob/dev/CHANGELOG.md',
// 'https://raw.githubusercontent.com/anusii/notepod/dev/CHANGELOG.md',
showDate: true,
// User specified text style - see branch on version_widget package
// fontSize: 12.0,
userTextStyle: TextStyle(
color: backgroundWhite,
fontSize: 12,
),
),
)
],
),
),
Container(
padding: const EdgeInsets.all(15),
child: Wrap(
runSpacing: 10,
children: [
ListTile(
leading: const Icon(Icons.note_add_outlined),
title: const Text('New Note'),
onTap: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => AppScreen(
title: topBarTitle,
childPage: NewNote(),
),
),
(Route<dynamic> route) =>
false, // This predicate ensures all previous routes are removed
);
},
),
ListTile(
leading: const Icon(Icons.view_list),
title: const Text('My Notes'),
onTap: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => AppScreen(
title: topBarTitle,
childPage: ListNotesScreen(),
),
),
(Route<dynamic> route) =>
false, // This predicate ensures all previous routes are removed
);
},
),
ListTile(
// 20250717 jm: Alternate icons for Shared Notes
// leading: const Icon(Icons.share_rounded),
// leading: const Icon(Icons.file_open_outlined),
leading: const Icon(Icons.groups),
title: const Text(sharedNotesTitle),
onTap: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => AppScreen(
title: topBarTitle,
childPage: SharedNotesScreen(),
// childPage: SharedNotes(),
),
),
(Route<dynamic> route) =>
false, // This predicate ensures all previous routes are removed
);
},
),
const Divider(
color: titleAsh,
),
ListTile(
leading: const Icon(Icons.settings),
title: const Text('Settings'),
onTap: () {
Navigator.of(context).pop();
},
),
ListTile(
leading: const Icon(Icons.exit_to_app),
title: const Text('Logout'),
onTap: webId.isEmpty
? null
: () async {
// Then direct to logout popup
await logoutPopup(context, const NotePod());
},
),
const Divider(
color: titleAsh,
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('About'),
onTap: () async {
// Get application getails
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String version = packageInfo.version;
showDialog<void>(
context: context,
builder: (BuildContext context) {
return _aboutDialog(appName, version);
},
);
},
),
],
),
),
],
),
);
}