Skip to content

Instantly share code, notes, and snippets.

@yaashwardhan
Last active January 10, 2023 17:22
Show Gist options
  • Save yaashwardhan/6dbf621609420db5ff92286197f32631 to your computer and use it in GitHub Desktop.
Save yaashwardhan/6dbf621609420db5ff92286197f32631 to your computer and use it in GitHub Desktop.

Revisions

  1. yaashwardhan revised this gist Jan 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion page2.dart(with modifications of value possible).dart
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ class _PageTwoState extends State<PageTwo> {
    Container(
    height: 400,
    width: double.infinity,
    color: passedColor.withOpacity(0.5),
    color: passedColor,
    ),
    Text('$passedColorName color was passed'),
    RaisedButton(
  2. yaashwardhan revised this gist Jan 3, 2021. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions page2.dart(with modifications of value possible).dart
    Original file line number Diff line number Diff line change
    @@ -34,8 +34,4 @@ class _PageTwoState extends State<PageTwo> {
    Navigator.pop(context);
    },
    child: Text('<- Go back'))
    ],
    ),
    );
    }
    }
    ],),);}
  3. yaashwardhan revised this gist Jan 3, 2021. 2 changed files with 1 addition and 1 deletion.
    1 change: 0 additions & 1 deletion page2.dart
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    import 'package:flutter/material.dart';
    import 'package:flutter/cupertino.dart';
    class PageTwo extends StatefulWidget {
    final Color passedColor;
    final String passedColorName;
    1 change: 1 addition & 0 deletions page2.dart(with modifications of value possible).dart
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    import 'package:flutter/material.dart';
    class PageTwo extends StatefulWidget {
    final Color passedColor;
    final String passedColorName;
  4. yaashwardhan revised this gist Jan 3, 2021. 2 changed files with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion page2.dart
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,8 @@ class _PageTwoState extends State<PageTwo> {
    },
    child: Text('<- Go back'))
    ],),);},}
    // Use this if u want to later make changes to the passed value in the code
    // Use this if u want to later make changes to the passed value in the code. Full code in the file below
    // NOTE: Here 'foo' means 'your value'
    // class MyStateful extends StatefulWidget {
    // final String foo;
    // const MyStateful({Key key, this.foo}): super(key: key);
  5. yaashwardhan revised this gist Jan 3, 2021. 1 changed file with 40 additions and 0 deletions.
    40 changes: 40 additions & 0 deletions page2.dart(with modifications of value possible))
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    class PageTwo extends StatefulWidget {
    final Color passedColor;
    final String passedColorName;
    const PageTwo({Key key, this.passedColor, this.passedColorName})
    : super(key: key);
    @override
    _PageTwoState createState() => _PageTwoState(
    passedColor: this.passedColor, passedColorName: this.passedColorName);
    }

    class _PageTwoState extends State<PageTwo> {
    Color passedColor;
    String passedColorName;
    _PageTwoState({this.passedColor, this.passedColorName});
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: Text('Page 2'),
    automaticallyImplyLeading: false, //to disable going back
    ),
    body: Column(
    children: [
    Container(
    height: 400,
    width: double.infinity,
    color: passedColor.withOpacity(0.5),
    ),
    Text('$passedColorName color was passed'),
    RaisedButton(
    color: Colors.grey,
    onPressed: () {
    Navigator.pop(context);
    },
    child: Text('<- Go back'))
    ],
    ),
    );
    }
    }
  6. yaashwardhan revised this gist Jan 3, 2021. 2 changed files with 5 additions and 30 deletions.
    19 changes: 3 additions & 16 deletions page1.dart
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,9 @@
    import 'package:flutter/material.dart';
    import 'page2.dart';

    class PageOne extends StatefulWidget {
    @override
    _PageOneState createState() => _PageOneState();
    }

    class _PageOneState extends State<PageOne> {
    @override
    Widget build(BuildContext context) {
    @@ -23,10 +21,7 @@ class _PageOneState extends State<PageOne> {
    builder: (_) => PageTwo(
    passedColor: Colors.pink,
    passedColorName: 'Pink',
    ),
    ),
    );
    },
    ),),);},
    child: Text('Pink')),
    RaisedButton(
    color: Colors.blueGrey,
    @@ -37,17 +32,9 @@ class _PageOneState extends State<PageOne> {
    builder: (_) => PageTwo(
    passedColor: Colors.blueGrey,
    passedColorName: 'Blue',
    ),
    ),
    );
    },
    ),),);},
    child: Text('Blue'),
    ),
    SizedBox(
    height: 250,
    )
    ],
    ),
    );
    }
    }
    )],),);}}
    16 changes: 2 additions & 14 deletions page2.dart
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    import 'package:flutter/material.dart';
    import 'package:flutter/cupertino.dart';

    class PageTwo extends StatefulWidget {
    final Color passedColor;
    final String passedColorName;
    @@ -10,7 +9,6 @@ class PageTwo extends StatefulWidget {
    @override
    _PageTwoState createState() => _PageTwoState();
    }

    class _PageTwoState extends State<PageTwo> {
    @override
    Widget build(BuildContext context) {
    @@ -33,28 +31,18 @@ class _PageTwoState extends State<PageTwo> {
    Navigator.pop(context);
    },
    child: Text('<- Go back'))
    ],
    ),
    );
    }
    }
    ],),);},}
    // Use this if u want to later make changes to the passed value in the code
    // class MyStateful extends StatefulWidget {
    // final String foo;

    // const MyStateful({Key key, this.foo}): super(key: key);

    // @override
    // _MyStatefulState createState() => _MyStatefulState(foo: this.foo);
    // }

    // class _MyStatefulState extends State<MyStateful> {
    // String foo;

    // _MyStatefulState({this.foo});

    // @override
    // Widget build(BuildContext context) {
    // return Text(foo);
    // }
    // }
    // },}
  7. yaashwardhan revised this gist Dec 30, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion main.dart
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    //Passing data to a Stateful Widget from another Stateful Widget
    import 'package:flutter/material.dart';
    import 'page1.dart';

  8. yaashwardhan revised this gist Dec 30, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    //Passing data to a Stateful Widget from another Stateful Widget
    import 'package:flutter/material.dart';
    import 'page1.dart';

  9. yaashwardhan created this gist Dec 30, 2020.
    21 changes: 21 additions & 0 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import 'package:flutter/material.dart';
    import 'page1.dart';

    void main() {
    runApp(MyApp());
    }

    class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    theme: ThemeData.dark(),
    home: Scaffold(
    appBar: AppBar(
    title: Text('Page 1'),
    ),
    body: PageOne(),
    ),
    );
    }
    }
    53 changes: 53 additions & 0 deletions page1.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    import 'package:flutter/material.dart';
    import 'page2.dart';

    class PageOne extends StatefulWidget {
    @override
    _PageOneState createState() => _PageOneState();
    }

    class _PageOneState extends State<PageOne> {
    @override
    Widget build(BuildContext context) {
    return Center(
    child: Column(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: [
    Text('Choose the color (value to be passed) of the Next Page:'),
    RaisedButton(
    color: Colors.pink,
    onPressed: () {
    Navigator.push(
    context,
    MaterialPageRoute(
    builder: (_) => PageTwo(
    passedColor: Colors.pink,
    passedColorName: 'Pink',
    ),
    ),
    );
    },
    child: Text('Pink')),
    RaisedButton(
    color: Colors.blueGrey,
    onPressed: () {
    Navigator.push(
    context,
    MaterialPageRoute(
    builder: (_) => PageTwo(
    passedColor: Colors.blueGrey,
    passedColorName: 'Blue',
    ),
    ),
    );
    },
    child: Text('Blue'),
    ),
    SizedBox(
    height: 250,
    )
    ],
    ),
    );
    }
    }
    60 changes: 60 additions & 0 deletions page2.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    import 'package:flutter/material.dart';
    import 'package:flutter/cupertino.dart';

    class PageTwo extends StatefulWidget {
    final Color passedColor;
    final String passedColorName;
    const PageTwo(
    {Key key, this.passedColor, this.passedColorName}) //key:key is used
    : super(key: key);
    @override
    _PageTwoState createState() => _PageTwoState();
    }

    class _PageTwoState extends State<PageTwo> {
    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: Text('Page 2'),
    automaticallyImplyLeading: false, //to disable going back
    ),
    body: Column(
    children: [
    Container(
    height: 400,
    width: double.infinity,
    color: widget.passedColor,
    ),
    Text('${widget.passedColorName} color was passed'),
    RaisedButton(
    color: Colors.grey,
    onPressed: () {
    Navigator.pop(context);
    },
    child: Text('<- Go back'))
    ],
    ),
    );
    }
    }
    // Use this if u want to later make changes to the passed value in the code
    // class MyStateful extends StatefulWidget {
    // final String foo;

    // const MyStateful({Key key, this.foo}): super(key: key);

    // @override
    // _MyStatefulState createState() => _MyStatefulState(foo: this.foo);
    // }

    // class _MyStatefulState extends State<MyStateful> {
    // String foo;

    // _MyStatefulState({this.foo});

    // @override
    // Widget build(BuildContext context) {
    // return Text(foo);
    // }
    // }