以下是含有BlocProvider的代码示例:
import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'bloc/counter_bloc.dart'; import 'view/counter_page.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Bloc Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: BlocProvider( create: (BuildContext context) => CounterBloc(), child: CounterPage(), ), ); } }