Skip to content

Instantly share code, notes, and snippets.

@lawreyios
Last active April 7, 2019 13:26
Show Gist options
  • Select an option

  • Save lawreyios/06cc0ca2c49b9fa5f807749be9fdf459 to your computer and use it in GitHub Desktop.

Select an option

Save lawreyios/06cc0ca2c49b9fa5f807749be9fdf459 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:flutter_global_variable/scoped_models/main.dart';
import 'package:flutter_global_variable/pages/page2.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MainModel _model = MainModel();
return ScopedModel<MainModel>(
model: _model,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
));
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${model.count}',
style: Theme.of(context).textTheme.display1,
),
SizedBox(height: 10.0),
RaisedButton(
padding: const EdgeInsets.all(8.0),
child: Text('Submit'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute<Page2>(
builder: (BuildContext context) => Page2()),
);
})
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
model.incrementCount();
}, //_incrementCounter(_model),
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment