@@ -43,8 +43,14 @@ final List<ExamplePage> _allPages = <ExamplePage>[
4343];
4444
4545class MapsDemo extends StatelessWidget {
46- //FIXME: Add your Mapbox access token here
47- static const String ACCESS_TOKEN = "YOUR_TOKEN_HERE" ;
46+ // FIXME: You need to pass in your access token via the command line argument
47+ // --dart-define=ACCESS_TOKEN=ADD_YOUR_TOKEN_HERE
48+ // It is also possible to pass it in while running the app via an IDE by
49+ // passing the same args there.
50+ //
51+ // Alternatively you can replace `String.fromEnvironment("ACCESS_TOKEN")`
52+ // in the following line with your access token directly.
53+ static const String ACCESS_TOKEN = String .fromEnvironment ("ACCESS_TOKEN" );
4854
4955 void _pushPage (BuildContext context, ExamplePage page) async {
5056 if (! kIsWeb) {
@@ -65,14 +71,42 @@ class MapsDemo extends StatelessWidget {
6571 Widget build (BuildContext context) {
6672 return Scaffold (
6773 appBar: AppBar (title: const Text ('MapboxMaps examples' )),
68- body: ListView .separated (
69- itemCount: _allPages.length,
70- separatorBuilder: (BuildContext context, int index) =>
71- const Divider (height: 1 ),
72- itemBuilder: (_, int index) => ListTile (
73- leading: _allPages[index].leading,
74- title: Text (_allPages[index].title),
75- onTap: () => _pushPage (context, _allPages[index]),
74+ body: ACCESS_TOKEN .isEmpty || ACCESS_TOKEN .contains ("YOUR_TOKEN" )
75+ ? buildAccessTokenWarning ()
76+ : ListView .separated (
77+ itemCount: _allPages.length,
78+ separatorBuilder: (BuildContext context, int index) =>
79+ const Divider (height: 1 ),
80+ itemBuilder: (_, int index) => ListTile (
81+ leading: _allPages[index].leading,
82+ title: Text (_allPages[index].title),
83+ onTap: () => _pushPage (context, _allPages[index]),
84+ ),
85+ ),
86+ );
87+ }
88+
89+ Widget buildAccessTokenWarning () {
90+ return Container (
91+ color: Colors .red[900 ],
92+ child: SizedBox .expand (
93+ child: Column (
94+ mainAxisAlignment: MainAxisAlignment .center,
95+ children: [
96+ "Please pass in your access token with" ,
97+ "--dart-define=ACCESS_TOKEN=ADD_YOUR_TOKEN_HERE" ,
98+ "passed into flutter run or add it to args in vscode's launch.json" ,
99+ ]
100+ .map ((text) => Padding (
101+ padding: EdgeInsets .all (8 ),
102+ child: Text (text,
103+ textAlign: TextAlign .center,
104+ style: TextStyle (
105+ fontSize: 14 ,
106+ fontWeight: FontWeight .bold,
107+ color: Colors .white)),
108+ ))
109+ .toList (),
76110 ),
77111 ),
78112 );
0 commit comments