simple_page_widgets.dart 13.2 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

class FirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open second route'),
          onPressed: () {
Jidong Chen's avatar
Jidong Chen committed
17
            print("open second page!");
yangwu.jia's avatar
yangwu.jia committed
18
            FlutterBoost.singleton.open("second").then((Map value) {
yangwu.jia's avatar
yangwu.jia committed
19 20
              print(
                  "call me when page is finished. did recieve second route result $value");
Jidong Chen's avatar
Jidong Chen committed
21
            });
Jidong Chen's avatar
init  
Jidong Chen committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
          },
        ),
      ),
    );
  }
}

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
40 41 42 43 44

            BoostContainerSettings settings =
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
                result: {"result": "data from second"});
Jidong Chen's avatar
init  
Jidong Chen committed
45
          },
Jidong Chen's avatar
Jidong Chen committed
46
          child: Text('Go back with result!'),
Jidong Chen's avatar
init  
Jidong Chen committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        ),
      ),
    );
  }
}

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
63
            FlutterBoost.singleton.open("second");
Jidong Chen's avatar
init  
Jidong Chen committed
64 65 66 67 68 69 70 71
          },
          child: Text('Open second route'),
        ),
      ),
    );
  }
}

yangwu.jia's avatar
yangwu.jia committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
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
94 95 96
class FlutterRouteWidget extends StatefulWidget {
  FlutterRouteWidget({this.params,this.message});
  final Map params;
97 98
  final String message;

yangwu.jia's avatar
yangwu.jia committed
99 100 101 102 103 104
  @override
  _FlutterRouteWidgetState createState() => _FlutterRouteWidgetState();
}

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

Jidong Chen's avatar
init  
Jidong Chen committed
106 107
  @override
  Widget build(BuildContext context) {
yangwu.jia's avatar
yangwu.jia committed
108
    final String message=widget.message;
Jidong Chen's avatar
init  
Jidong Chen committed
109 110
    return Scaffold(
      appBar: AppBar(
yangwu.jia's avatar
yangwu.jia committed
111 112 113 114
        brightness:Brightness.light,
        backgroundColor: Colors.white,
        textTheme:new TextTheme(title: TextStyle(color: Colors.black)) ,

Jidong Chen's avatar
init  
Jidong Chen committed
115 116
        title: Text('flutter_boost_example'),
      ),
yangwu.jia's avatar
yangwu.jia committed
117 118 119 120 121 122 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
      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
                      .open("sample://nativePage", urlParams: {
                    "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
170
                        'open first',
yangwu.jia's avatar
yangwu.jia committed
171 172 173 174 175 176
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
177
                      .open("first", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
178 179 180 181 182 183 184 185 186
                    "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
187
                        'open second',
yangwu.jia's avatar
yangwu.jia committed
188 189 190 191 192 193
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
194
                      .open("second", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
195 196 197 198 199 200 201 202 203
                    "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
204
                        'open tab',
yangwu.jia's avatar
yangwu.jia committed
205 206 207 208 209 210
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
211
                      .open("tab", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
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
                    "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
                      .open("sample://flutterPage", urlParams: {
                    "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: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (_) => PushWidget()));
                  },
                ),
yangwu.jia's avatar
yangwu.jia committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

              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: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (_) => PlatformRouteWidget()));
                },
              ),
yangwu.jia's avatar
yangwu.jia committed
261 262 263 264 265 266 267 268 269 270 271 272 273
                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
274
            ),
yangwu.jia's avatar
yangwu.jia committed
275 276

        ),
Jidong Chen's avatar
init  
Jidong Chen committed
277 278 279 280 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 308 309 310 311 312 313 314 315 316 317 318 319 320 321
      ),
    );
  }
}

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
322
            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
Jidong Chen's avatar
init  
Jidong Chen committed
323 324 325 326 327 328 329 330 331 332
          ),
          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
333
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
334 335 336 337 338 339 340 341 342 343
          ),
          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
344 345
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
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

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();

372 373 374 375 376 377 378 379 380
//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
381 382 383 384 385 386 387 388 389 390 391
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _backPressedListenerUnsub?.call();
  }

  @override
  Widget build(BuildContext context) {
hym's avatar
hym committed
392
    return FlutterRouteWidget(message: "Pushed Widget");
393 394
  }
}