Skip to content

Instantly share code, notes, and snippets.

@shibby360
Last active March 10, 2023 22:41
Show Gist options
  • Save shibby360/2eb4214ff099f9e1d396f1365bae9dbb to your computer and use it in GitHub Desktop.
Save shibby360/2eb4214ff099f9e1d396f1365bae9dbb to your computer and use it in GitHub Desktop.
minibs
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'dart:math';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => MyAppState(),
child: MaterialApp(
title: 'Brawl Stars Box Simulator',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange, primary: Colors.orange),
),
home: MyHomePage(),
),
);
}
}
class MyAppState extends ChangeNotifier {
var msg = '';
var rng = Random();
void roll() {
var msgs = ['You got coins', 'You got coins', 'brawler'];
var msgindex = rng.nextInt(msgs.length);
var endmsg = msgs[msgindex];
if(endmsg == 'brawler') {
var types = ['rare', 'rare', 'rare', 'rare', 'rare', 'super rare', 'super rare', 'super rare', 'super rare', 'epic', 'epic', 'epic', 'mythic', 'mythic', 'legendary'];
var typeind = rng.nextInt(types.length);
endmsg = types[typeind];
}
notifyListeners();
msg = endmsg;
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0;
@override
Widget build(BuildContext context) {
Widget page;
var theme = Theme.of(context);
switch (selectedIndex) {
case 0:
page = HomePage();
break;
case 1:
page = BoxPage();
break;
case 2:
page = Placeholder();
break;
default:
throw UnimplementedError('no widget for $selectedIndex');
}
return LayoutBuilder(
builder: (context, constraints) {
return Scaffold(
body: Row(
children: [
SafeArea(
child: NavigationRail(
extended: constraints.maxWidth >= 600,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.home),
selectedIcon: Icon(Icons.home, color:theme.colorScheme.primary),
label: Text('Home'),
),
NavigationRailDestination(
icon: Icon(Icons.add_box),
selectedIcon: Icon(Icons.add_box, color:theme.colorScheme.primary),
label: Text('Box'),
),
NavigationRailDestination(
icon:Icon(Icons.favorite),
selectedIcon: Icon(Icons.favorite, color:theme.colorScheme.primary),
label:Text('Battle')
)
],
selectedIndex: selectedIndex,
onDestinationSelected: (value) {
setState(() {
selectedIndex = value;
});
},
),
),
Expanded(
child: Container(
color: Theme.of(context).colorScheme.primaryContainer,
child: page,
),
),
],
),
);
}
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Placeholder()
);
}
}
class BoxPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var theme = Theme.of(context);
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(appState.msg),
ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: theme.colorScheme.onPrimary,
backgroundColor: theme.colorScheme.primary
),
onPressed: () {
appState.roll();
},
child: Text('Open'),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment