page_widgets.dart 14 KB
Newer Older
yangwu.jia's avatar
yangwu.jia committed
1 2 3 4 5 6 7 8 9
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';

class FirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
10
        title: const Text('First Route'),
yangwu.jia's avatar
yangwu.jia committed
11 12
      ),
      body: Center(
13
        child: Column(
yangwu.jia's avatar
yangwu.jia committed
14
          mainAxisAlignment: MainAxisAlignment.center,
15
          children: <Widget>[
yangwu.jia's avatar
yangwu.jia committed
16
            RaisedButton(
17 18 19 20 21
              child: const Text('First'),
              onPressed: () {
                print('open second page!');
                FlutterBoost.singleton
                    .open('second')
22
                    .then((Map<dynamic, dynamic> value) {
23 24 25 26 27 28 29 30 31 32 33 34
                  print(
                      'call me when page is finished. did recieve second route result $value');
                });
              },
            ),
            RaisedButton(
              child: const Text('Present second route'),
              onPressed: () {
                print('Present second page!');
                FlutterBoost.singleton.open('second',
                    urlParams: <String, dynamic>{
                      'present': true
35
                    }).then((Map<dynamic, dynamic> value) {
36 37 38 39 40 41
                  print(
                      'call me when page is finished. did recieve second route result $value');
                });
              },
            ),
          ],
yangwu.jia's avatar
yangwu.jia committed
42 43 44 45 46 47 48 49 50 51 52 53
        ),
      ),
    );
  }
}

class EmbededFirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
54
          child: const Text('Open second route'),
yangwu.jia's avatar
yangwu.jia committed
55
          onPressed: () {
56 57 58
            print('open second page!');
            FlutterBoost.singleton
                .open('second')
59
                .then((Map<dynamic, dynamic> value) {
yangwu.jia's avatar
yangwu.jia committed
60
              print(
61
                  'call me when page is finished. did recieve second route result $value');
yangwu.jia's avatar
yangwu.jia committed
62 63 64 65 66 67 68 69 70 71 72 73 74
            });
          },
        ),
      ),
    );
  }
}

class SecondRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
75
        title: const Text('Second'),
yangwu.jia's avatar
yangwu.jia committed
76 77 78 79 80 81
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            // Navigate back to first route when tapped.

82
            final BoostContainerSettings settings =
yangwu.jia's avatar
yangwu.jia committed
83 84
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
85
                result: <String, dynamic>{'result': 'data from second'});
yangwu.jia's avatar
yangwu.jia committed
86
          },
87
          child: const Text('Go back with result!'),
yangwu.jia's avatar
yangwu.jia committed
88 89 90 91 92 93 94 95 96 97 98
        ),
      ),
    );
  }
}

class TabRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
99
        title: const Text('Tab Route'),
yangwu.jia's avatar
yangwu.jia committed
100 101 102 103
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
104
            FlutterBoost.singleton.open('second');
yangwu.jia's avatar
yangwu.jia committed
105
          },
106
          child: const Text('Open second route'),
yangwu.jia's avatar
yangwu.jia committed
107 108 109 110 111 112 113
        ),
      ),
    );
  }
}

class FlutterRouteWidget extends StatefulWidget {
114 115 116
  const FlutterRouteWidget({this.params, this.message});

  final Map<String, dynamic> params;
yangwu.jia's avatar
yangwu.jia committed
117 118 119 120 121 122 123 124 125
  final String message;

  @override
  _FlutterRouteWidgetState createState() => _FlutterRouteWidgetState();
}

class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
  @override
  Widget build(BuildContext context) {
126
    final String message = widget.message;
yangwu.jia's avatar
yangwu.jia committed
127 128
    return Scaffold(
      appBar: AppBar(
129
        brightness: Brightness.light,
yangwu.jia's avatar
yangwu.jia committed
130
        backgroundColor: Colors.white,
131 132
        textTheme: TextTheme(title: TextStyle(color: Colors.black)),
        title: const Text('flutter_boost_example'),
yangwu.jia's avatar
yangwu.jia committed
133 134
      ),
      body: SingleChildScrollView(
135 136 137 138 139 140 141 142 143 144 145
        child: Container(
          margin: const EdgeInsets.all(24.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: const EdgeInsets.only(top: 10.0, bottom: 20.0),
                child: Text(
                  message ??
                      'This is a flutter activity \n params:${widget.params}',
                  style: TextStyle(fontSize: 28.0, color: Colors.blue),
yangwu.jia's avatar
yangwu.jia committed
146
                ),
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
                alignment: AlignmentDirectional.center,
              ),
              const CupertinoTextField(
                prefix: Icon(
                  CupertinoIcons.person_solid,
                  color: CupertinoColors.lightBackgroundGray,
                  size: 28.0,
                ),
                padding: EdgeInsets.symmetric(horizontal: 6.0, vertical: 12.0),
                clearButtonMode: OverlayVisibilityMode.editing,
                textCapitalization: TextCapitalization.words,
                autocorrect: false,
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                        width: 0.0, color: CupertinoColors.inactiveGray),
yangwu.jia's avatar
yangwu.jia committed
163
                  ),
164 165 166 167 168 169 170 171 172 173 174
                ),
                placeholder: 'Name',
              ),
              InkWell(
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  margin: const EdgeInsets.all(8.0),
                  color: Colors.yellow,
                  child: Text(
                    'open native page',
                    style: TextStyle(fontSize: 22.0, color: Colors.black),
yangwu.jia's avatar
yangwu.jia committed
175 176 177
                  ),
                ),

178 179 180 181 182 183 184
                ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                ///例如:sample://nativePage?aaa=bbb
                onTap: () => FlutterBoost.singleton.open(
                  'sample://nativePage',
                  urlParams: <String, dynamic>{
                    'query': <String, dynamic>{'aaa': 'bbb'},
                  },
yangwu.jia's avatar
yangwu.jia committed
185
                ),
186 187 188 189 190 191 192 193 194 195
              ),
              InkWell(
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  margin: const EdgeInsets.all(8.0),
                  color: Colors.yellow,
                  child: Text(
                    'open first',
                    style: TextStyle(fontSize: 22.0, color: Colors.black),
                  ),
yangwu.jia's avatar
yangwu.jia committed
196 197
                ),

198 199 200 201 202 203 204
                ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                ///例如:sample://nativePage?aaa=bbb
                onTap: () => FlutterBoost.singleton.open(
                  'first',
                  urlParams: <String, dynamic>{
                    'query': <String, dynamic>{'aaa': 'bbb'},
                  },
yangwu.jia's avatar
yangwu.jia committed
205
                ),
206 207 208 209 210 211 212 213 214 215
              ),
              InkWell(
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  margin: const EdgeInsets.all(8.0),
                  color: Colors.yellow,
                  child: Text(
                    'open second',
                    style: TextStyle(fontSize: 22.0, color: Colors.black),
                  ),
yangwu.jia's avatar
yangwu.jia committed
216 217
                ),

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
                ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                ///例如:sample://nativePage?aaa=bbb
                onTap: () => FlutterBoost.singleton.open(
                  'second',
                  urlParams: <String, dynamic>{
                    'query': <String, dynamic>{'aaa': 'bbb'},
                  },
                ),
              ),
              InkWell(
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  margin: const EdgeInsets.all(8.0),
                  color: Colors.yellow,
                  child: Text(
                    'open tab',
                    style: TextStyle(fontSize: 22.0, color: Colors.black),
                  ),
yangwu.jia's avatar
yangwu.jia committed
236
                ),
237 238 239 240 241 242 243

                ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                ///例如:sample://nativePage?aaa=bbb
                onTap: () => FlutterBoost.singleton.open(
                  'tab',
                  urlParams: <String, dynamic>{
                    'query': <String, dynamic>{'aaa': 'bbb'}
yangwu.jia's avatar
yangwu.jia committed
244 245
                  },
                ),
246 247 248 249 250 251 252 253 254 255 256
              ),
              InkWell(
                child: Container(
                  padding: const EdgeInsets.all(8.0),
                  margin: const EdgeInsets.all(8.0),
                  color: Colors.yellow,
                  child: Text(
                    'open flutter page',
                    style: TextStyle(fontSize: 22.0, color: Colors.black),
                  ),
                ),
yangwu.jia's avatar
yangwu.jia committed
257

258 259 260 261 262 263 264 265 266
                ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                ///例如:sample://nativePage?aaa=bbb
                onTap: () => FlutterBoost.singleton.open(
                  'sample://flutterPage',
                  urlParams: <String, dynamic>{
                    'query': <String, dynamic>{'aaa': 'bbb'}
                  },
                ),
              ),
yangwu.jia's avatar
yangwu.jia committed
267 268 269 270 271 272
              InkWell(
                child: Container(
                    padding: const EdgeInsets.all(8.0),
                    margin: const EdgeInsets.all(8.0),
                    color: Colors.yellow,
                    child: Text(
273
                      'push flutter widget',
yangwu.jia's avatar
yangwu.jia committed
274 275 276
                      style: TextStyle(fontSize: 22.0, color: Colors.black),
                    )),
                onTap: () {
277 278 279 280
                  Navigator.push<dynamic>(
                    context,
                    MaterialPageRoute<dynamic>(builder: (_) => PushWidget()),
                  );
yangwu.jia's avatar
yangwu.jia committed
281 282
                },
              ),
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
              InkWell(
                child: Container(
                    padding: const EdgeInsets.all(8.0),
                    margin: const EdgeInsets.all(8.0),
                    color: Colors.yellow,
                    child: Text(
                      'push Platform demo',
                      style: TextStyle(fontSize: 22.0, color: Colors.black),
                    )),
                onTap: () {},
              ),
              InkWell(
                child: Container(
                    padding: const EdgeInsets.all(8.0),
                    margin: const EdgeInsets.all(8.0),
                    color: Colors.yellow,
                    child: Text(
                      'open flutter fragment page',
                      style: TextStyle(fontSize: 22.0, color: Colors.black),
                    )),
                onTap: () =>
                    FlutterBoost.singleton.open('sample://flutterFragmentPage'),
              ),
            ],
          ),
yangwu.jia's avatar
yangwu.jia committed
308 309 310 311 312 313 314
        ),
      ),
    );
  }
}

class FragmentRouteWidget extends StatelessWidget {
315
  const FragmentRouteWidget(this.params);
yangwu.jia's avatar
yangwu.jia committed
316

317
  final Map<String, dynamic> params;
yangwu.jia's avatar
yangwu.jia committed
318 319 320 321 322

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
323
        title: const Text('flutter_boost_example'),
yangwu.jia's avatar
yangwu.jia committed
324 325 326 327 328 329 330
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
331
              'This is a flutter fragment',
yangwu.jia's avatar
yangwu.jia committed
332 333 334 335 336 337 338
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
339
              '${params['tag']}' ?? '',
yangwu.jia's avatar
yangwu.jia committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
354
            onTap: () => FlutterBoost.singleton.open('sample://nativePage'),
yangwu.jia's avatar
yangwu.jia committed
355 356 357 358 359 360 361 362 363 364
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
365
            onTap: () => FlutterBoost.singleton.open('sample://flutterPage'),
yangwu.jia's avatar
yangwu.jia committed
366 367 368 369 370 371 372 373 374 375 376
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
377
                FlutterBoost.singleton.open('sample://flutterFragmentPage'),
yangwu.jia's avatar
yangwu.jia committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
          )
        ],
      ),
    );
  }
}

class PushWidget extends StatefulWidget {
  @override
  _PushWidgetState createState() => _PushWidgetState();
}

class _PushWidgetState extends State<PushWidget> {
  VoidCallback _backPressedListenerUnsub;

  @override
  void initState() {
395
    // TODO(unknown): implement initState
yangwu.jia's avatar
yangwu.jia committed
396 397 398 399 400
    super.initState();
  }

  @override
  void didChangeDependencies() {
401
    // TODO(unknown): implement didChangeDependencies
yangwu.jia's avatar
yangwu.jia committed
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
    super.didChangeDependencies();

//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
  }

  @override
  void dispose() {
417
    // TODO(unknown): implement dispose
yangwu.jia's avatar
yangwu.jia committed
418 419 420 421 422 423
    super.dispose();
    _backPressedListenerUnsub?.call();
  }

  @override
  Widget build(BuildContext context) {
424
    return const FlutterRouteWidget(message: 'Pushed Widget');
yangwu.jia's avatar
yangwu.jia committed
425 426
  }
}