simple_page_widgets.dart 19.3 KB
Newer Older
yangwu.jia's avatar
yangwu.jia committed
1
import 'package:flutter/cupertino.dart';
Jidong Chen's avatar
init  
Jidong Chen committed
2
import 'package:flutter/material.dart';
yangwu.jia's avatar
yangwu.jia committed
3
import 'package:flutter_boost/flutter_boost.dart';
yangwu.jia's avatar
yangwu.jia committed
4
import 'package:flutter_boost_example/platform_view.dart';
Jidong Chen's avatar
init  
Jidong Chen committed
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
class FirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _FirstRouteWidgetState();
  }
}
class _FirstRouteWidgetState extends State<FirstRouteWidget>{
  _FirstRouteWidgetState();

  @override
  void initState() {
    print('initState');
    super.initState();
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(FirstRouteWidget oldWidget) {
    print('didUpdateWidget');
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  @override
  void dispose() {
    print('[XDEBUG] - FirstRouteWidget is disposing~');
    super.dispose();
  }

Jidong Chen's avatar
init  
Jidong Chen committed
45 46 47 48 49 50 51
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
余玠's avatar
余玠 committed
52 53 54 55 56
        child:
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: 
          <Widget>[
57 58 59 60 61 62
            RaisedButton(
                child: Text('Open native page'),
                onPressed: () {
                  print("open natve page!");
                  FlutterBoost.singleton.open("native").then((Map value) {
                    print(
余玠's avatar
余玠 committed
63
                        "call me when page is finished. did recieve native route result $value");
64 65 66
                  });
                },
              ),
67 68 69 70 71 72 73 74 75 76 77 78
              RaisedButton(
                child: Text('Open FF route'),
                onPressed: () {
                  print("open FF page!");
                  FlutterBoost.singleton.open("firstFirst").then((Map value) {
                    print(
                        "call me when page is finished. did recieve FF route result $value");
                  });
                },
              ),
              RaisedButton(
                child: Text('Open second route1'),
余玠's avatar
余玠 committed
79 80 81 82 83 84 85 86 87 88
                onPressed: () {
                  print("open second page!");
                  FlutterBoost.singleton.open("second").then((Map value) {
                    print(
                        "call me when page is finished. did recieve second route result $value");
                  });
                },
              ),

              RaisedButton(
余玠's avatar
余玠 committed
89 90 91 92 93 94 95 96 97 98
                  child: Text('Present second stateful route'),
                  onPressed: () {
                    print("Present second stateful page!");
                    FlutterBoost.singleton.open("secondStateful",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) {
                      print(
                          "call me when page is finished. did recieve second stateful route result $value");
                    });
                  },
                ),
                RaisedButton(
余玠's avatar
余玠 committed
99 100 101
                  child: Text('Present second route'),
                  onPressed: () {
                    print("Present second page!");
justin's avatar
justin committed
102
                    FlutterBoost.singleton.open("second",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) {
余玠's avatar
余玠 committed
103 104 105 106 107 108
                      print(
                          "call me when page is finished. did recieve second route result $value");
                    });
                  },
                ),
            ],
Jidong Chen's avatar
init  
Jidong Chen committed
109 110 111 112 113
        ),
      ),
    );
  }
}
114 115 116 117 118 119 120 121 122
class FirstFirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _FirstFirstRouteWidgetState();
  }
}

class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{
  _FirstFirstRouteWidgetState();
Jidong Chen's avatar
init  
Jidong Chen committed
123

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  @override
  void initState() {
    print('initState');
    super.initState();
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(FirstFirstRouteWidget oldWidget) {
    print('didUpdateWidget');
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  @override
  void dispose() {
    print('[XDEBUG] - FirstFirstRouteWidget is disposing~');
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open first route'),
          onPressed: () {

            print("open first page again!");
            FlutterBoost.singleton.open("first").then((Map value){
              print("did recieve first route result");
              print("did recieve first route result $value");
            });

          },
        ),
      ),
    );
  }
}

class EmbededFirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _EmbededFirstRouteWidgetState();
  }

}

class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> {
188 189
  @override
  Widget build(BuildContext context) {
190
    print('_EmbededFirstRouteWidgetState build called!');
191 192 193
    return Scaffold(
      body: Center(
        child: RaisedButton(
194
          child: Text('Open second route2'),
195 196 197 198 199 200 201 202 203 204 205
          onPressed: () {
            print("open second page!");
            FlutterBoost.singleton.open("second").then((Map value) {
              print(
                  "call me when page is finished. did recieve second route result $value");
            });
          },
        ),
      ),
    );
  }
206 207
  @override
  void dispose() {
余玠's avatar
余玠 committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    print('[XDEBUG]:_EmbededFirstRouteWidgetState disposing~');
    super.dispose();
  }
}

class SecondStatefulRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SecondStatefulRouteWidgetState();
  }
}
class _SecondStatefulRouteWidgetState extends State<SecondStatefulRouteWidget>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("SecondStateful Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            // Navigate back to first route when tapped.

            BoostContainerSettings settings =
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
                result: <dynamic,dynamic>{"result": "data from second"});
          },
          child: Text('Go back with result!'),
        ),
      ),
    );
  }

  @override
  void dispose() {
    print('[XDEBUG]:SecondStatefulRouteWidget disposing~');
246 247
    super.dispose();
  }
248 249
}

Jidong Chen's avatar
init  
Jidong Chen committed
250 251 252 253 254 255 256 257 258 259 260
class SecondRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            // Navigate back to first route when tapped.
hym's avatar
hym committed
261 262 263 264

            BoostContainerSettings settings =
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
justin's avatar
justin committed
265
                result: <dynamic,dynamic>{"result": "data from second"});
Jidong Chen's avatar
init  
Jidong Chen committed
266
          },
Jidong Chen's avatar
Jidong Chen committed
267
          child: Text('Go back with result!'),
Jidong Chen's avatar
init  
Jidong Chen committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
        ),
      ),
    );
  }
}

class TabRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Tab Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
yangwu.jia's avatar
yangwu.jia committed
284
            FlutterBoost.singleton.open("second");
Jidong Chen's avatar
init  
Jidong Chen committed
285
          },
286
          child: Text('Open second route3'),
Jidong Chen's avatar
init  
Jidong Chen committed
287 288 289 290 291 292
        ),
      ),
    );
  }
}

yangwu.jia's avatar
yangwu.jia committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
class PlatformRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:Text("Platform Route"),
      ),
      body: Center(
        child: RaisedButton(
          child: TextView(),
          onPressed: () {
            print("open second page!");
            FlutterBoost.singleton.open("second").then((Map value) {
              print(
                  "call me when page is finished. did recieve second route result $value");
            });
          },
        ),
      ),
    );
  }
}
yangwu.jia's avatar
yangwu.jia committed
315 316 317
class FlutterRouteWidget extends StatefulWidget {
  FlutterRouteWidget({this.params,this.message});
  final Map params;
318 319
  final String message;

yangwu.jia's avatar
yangwu.jia committed
320 321 322 323 324 325
  @override
  _FlutterRouteWidgetState createState() => _FlutterRouteWidgetState();
}

class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
  final TextEditingController _usernameController = TextEditingController();
326

Jidong Chen's avatar
init  
Jidong Chen committed
327 328
  @override
  Widget build(BuildContext context) {
yangwu.jia's avatar
yangwu.jia committed
329
    final String message=widget.message;
Jidong Chen's avatar
init  
Jidong Chen committed
330 331
    return Scaffold(
      appBar: AppBar(
yangwu.jia's avatar
yangwu.jia committed
332 333 334 335
        brightness:Brightness.light,
        backgroundColor: Colors.white,
        textTheme:new TextTheme(title: TextStyle(color: Colors.black)) ,

Jidong Chen's avatar
init  
Jidong Chen committed
336 337
        title: Text('flutter_boost_example'),
      ),
yangwu.jia's avatar
yangwu.jia committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
      body: SingleChildScrollView(
        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),
                  ),
                  alignment: AlignmentDirectional.center,
                ),
//                Expanded(child: Container()),
                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)),
                  ),
                  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),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
381
                      .open("sample://nativePage", urlParams: <dynamic,dynamic>{
yangwu.jia's avatar
yangwu.jia committed
382 383 384 385 386 387 388 389 390
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
391
                        'open first',
yangwu.jia's avatar
yangwu.jia committed
392 393 394 395 396 397
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
398
                      .open("first", urlParams: <dynamic,dynamic>{
yangwu.jia's avatar
yangwu.jia committed
399 400 401 402 403 404 405 406 407
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
408
                        'open second',
yangwu.jia's avatar
yangwu.jia committed
409 410 411 412 413 414
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
415
                      .open("second", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
416 417 418 419 420 421 422 423 424
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
425
                        'open tab',
yangwu.jia's avatar
yangwu.jia committed
426 427 428 429 430 431
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
432
                      .open("tab", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
                    "query": {"aaa": "bbb"}
                  }),
                ),
                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),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
449
                      .open("sample://flutterPage", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
450 451 452 453 454 455 456 457 458 459 460 461 462
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
                        'push flutter widget',
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),
                  onTap: () {
justin's avatar
justin committed
463 464
                  Navigator.push<dynamic>(context,
                        MaterialPageRoute<dynamic>(builder: (_) => PushWidget()));
yangwu.jia's avatar
yangwu.jia committed
465 466
                  },
                ),
yangwu.jia's avatar
yangwu.jia committed
467 468 469 470 471 472 473 474 475 476 477

              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: () {
justin's avatar
justin committed
478 479
                  Navigator.push<dynamic>(context,
                      MaterialPageRoute<dynamic>(builder: (_) => PlatformRouteWidget()));
yangwu.jia's avatar
yangwu.jia committed
480 481
                },
              ),
yangwu.jia's avatar
yangwu.jia committed
482 483 484 485 486 487 488 489 490 491 492 493 494
                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"),
                ),
              ],
Jidong Chen's avatar
init  
Jidong Chen committed
495
            ),
yangwu.jia's avatar
yangwu.jia committed
496 497

        ),
Jidong Chen's avatar
init  
Jidong Chen committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
      ),
    );
  }
}

class FragmentRouteWidget extends StatelessWidget {
  final Map params;

  FragmentRouteWidget(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              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),
                )),
hym's avatar
hym committed
543
            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
Jidong Chen's avatar
init  
Jidong Chen committed
544 545 546 547 548 549 550 551 552 553
          ),
          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),
                )),
hym's avatar
hym committed
554
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
555 556 557 558 559 560 561 562 563 564
          ),
          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),
                )),
hym's avatar
hym committed
565 566
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
567 568 569 570 571 572
          )
        ],
      ),
    );
  }
}
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592

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

class _PushWidgetState extends State<PushWidget> {
  VoidCallback _backPressedListenerUnsub;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();

593 594 595 596 597 598 599 600 601
//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
602 603 604 605 606
  }

  @override
  void dispose() {
    // TODO: implement dispose
余玠's avatar
余玠 committed
607
    print('[XDEBUG] - PushWidget is disposing~');
608 609 610 611 612 613
    super.dispose();
    _backPressedListenerUnsub?.call();
  }

  @override
  Widget build(BuildContext context) {
hym's avatar
hym committed
614
    return FlutterRouteWidget(message: "Pushed Widget");
615 616
  }
}